from sys import stdin

d_num = int(stdin.readline().strip())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, stdin.readline().split())
    for v in neighbors:
        graph[u].append(v)

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited: stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave) from sys import stdin d_num = int(stdin.readline().strip()) d_num int(stdin.readline().strip()) int stdin.readline().strip() stdin.readline().strip stdin.readline() stdin.readline stdin readline strip [] for _ in range(d_num+1) for _ in range(d_num+1) _ range(d_num+1) range d_num+1 d_num 1 for _ in range(d_num+1) [] graph = [[] for _ in range(d_num+1)] graph [[] for _ in range(d_num+1)] for _ in range(d_num):
    u, k, *neighbors = map(int, stdin.readline().split())
    for v in neighbors:
        graph[u].append(v) _ range(d_num) range d_num u, k, *neighbors = map(int, stdin.readline().split()) u map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split k *neighbors neighbors for v in neighbors:
        graph[u].append(v) v neighbors graph[u].append(v) [u].append [u] graph u append v visited = set() visited set() set None for _ in range(d_num+1) for _ in range(d_num+1) _ range(d_num+1) range d_num+1 d_num 1 for _ in range(d_num+1) None timestamps = [None for _ in range(d_num+1)] timestamps [None for _ in range(d_num+1)] def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 dfs visited.add(u) visited.add visited add u entry = stmp entry stmp stmp += 1 stmp 1 for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

     v graph[u] graph u if v not in visited:
            stmp = dfs(v, stmp)

     v not in visited v visited stmp = dfs(v, stmp) stmp dfs(v, stmp) dfs v stmp timestamps[u] = entry, stmp timestamps[u] timestamps u timestamps[u] = entry, stmp entry stmp return stmp+1 stmp+1 stmp 1 u u stmp stmp stmp = 1 stmp 1 for v in range(1, d_num+1):
    if v not in visited: stmp = dfs(v, stmp) v range(1, d_num+1) range 1 d_num+1 d_num 1 if v not in visited: stmp = dfs(v, s v not in visited v visited for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave) num (entry, leave) entry leave enumerate(timestamps[1:], 1) enumerate timestamps[1:] timestamps 1: 1 1 print(num, entry, leave) print num entry leave u, k, *neighbors = map(int, stdin.readline().split()) map(int, stdin.readline().split()) u visited = set() set() visited graph = [[] for _ in range(d_num+1)] [[] for _ in range(d_num+1)] graph def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 dfs timestamps = [None for _ in range(d_num+1)] [None for _ in range(d_num+1)] timestamps d_num = int(stdin.readline().strip()) int(stdin.readline().strip()) d_num stmp = 1 1 stmp k, *neighbors = map(int, stdin.readline().split()) map(int, stdin.readline().split()) k
from sys import stdin

d_num = int(stdin.readline().strip())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, stdin.readline().split())
    for v in neighbors:
        graph[u].append(v)

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited: stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave)