import sys

sys.setrecursionlimit(10 ** 8)
n = int(input())

graph = [[] for _ in range(n)]
for i in range(n):
    graph[i] = list(map(lambda x: x - 1, list(map(int, input().split()))[2:]))

timestamp = [[] for _ in range(n)]
visited = [False] * n
cnt = 0


def dfs(v):
    global visited
    global cnt
    global timestamp
    cnt += 1
    timestamp[v].append(cnt)
    visited[v] = True
    for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
    cnt += 1
    timestamp[v].append(cnt)


dfs(0)

while False in visited:
    nxt = visited.index(False)
    dfs(nxt)


for i, (d, f) in enumerate(timestamp, 1):
    print(i, d, f)
 import sys sys sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] for i in range(n):
    graph[i] = list(map(lambda x: x - 1, list(map(int, input().split()))[2:])) i range(n) range n graph[i] = list(map(lambda x: x - 1, list(map(int, input().split()))[2:])) graph[i] graph i list(map(lambda x: x - 1, list(map(int, input().split()))[2:])) list map(lambda x: x - 1, list(map(int, input().split()))[2:]) map lambda x: x - 1 x - 1 x 1 x list(map(int, input().split()))[2:] (map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 2: 2 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] timestamp = [[] for _ in range(n)] timestamp [[] for _ in range(n)] visited = [False] * n visited [False] * n [False] False n cnt = 0 cnt 0 def dfs(v):
    global visited
    global cnt
    global timestamp
    cnt += 1
    timestamp[v].append(cnt)
    visited[v] = True
    for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
    cnt += 1
    timestamp[v].append(cnt) dfs global visited global cnt global timestamp cnt += 1 cnt 1 timestamp[v].append(cnt) [v].append [v] timestamp v append cnt visited[v] = True visited[v] visited v True for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
     to graph[v] graph v if visited[to]:
            continue
        else:
            dfs(to)
     visited[to] visited to continue dfs(to) dfs to cnt += 1 cnt 1 timestamp[v].append(cnt) [v].append [v] timestamp v append cnt v v dfs(0) dfs 0 while False in visited:
    nxt = visited.index(False)
    dfs(nxt) False in visited False visited nxt = visited.index(False) nxt visited.index(False) visited.index visited index False dfs(nxt) dfs nxt for i, (d, f) in enumerate(timestamp, 1):
    print(i, d, f) i (d, f) d f enumerate(timestamp, 1) enumerate timestamp 1 print(i, d, f) print i d f n = int(input()) int(input()) n timestamp = [[] for _ in range(n)] [[] for _ in range(n)] timestamp def dfs(v):
    global visited
    global cnt
    global timestamp
    cnt += 1
    timestamp[v].append(cnt)
    visited[v] = True
    for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
    cnt += 1
    timestamp[v].append(cnt) def dfs(v):
    global visited
    global cnt
    global timestamp
    cnt += 1
    timestamp[v].append(cnt)
    visited[v] = True
    for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
    cnt += 1
    timestamp[v].append(cnt) dfs cnt = 0 0 cnt graph = [[] for _ in range(n)] [[] for _ in range(n)] graph nxt = visited.index(False) visited.index(False) nxt visited = [False] * n [False] * n visited
import sys

sys.setrecursionlimit(10 ** 8)
n = int(input())

graph = [[] for _ in range(n)]
for i in range(n):
    graph[i] = list(map(lambda x: x - 1, list(map(int, input().split()))[2:]))

timestamp = [[] for _ in range(n)]
visited = [False] * n
cnt = 0


def dfs(v):
    global visited
    global cnt
    global timestamp
    cnt += 1
    timestamp[v].append(cnt)
    visited[v] = True
    for to in graph[v]:
        if visited[to]:
            continue
        else:
            dfs(to)
    cnt += 1
    timestamp[v].append(cnt)


dfs(0)

while False in visited:
    nxt = visited.index(False)
    dfs(nxt)


for i, (d, f) in enumerate(timestamp, 1):
    print(i, d, f)

