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

d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 0

def dfs(now, prev, graph, d, f, time):
    if d[now] != 0:
        return d, f, time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
    return d, f, time



for i in range(n):
    d, f, time = dfs(i, 0, graph, d, f, time)
    print(i+1, d[i], f[i])
 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):
    in_list = list(map(int, input().split()))
    u = in_list[0]
    graph[u - 1] = in_list[2:] i range(n) range n in_list = list(map(int, input().split())) in_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = in_list[0] u in_list[0] in_list 0 graph[u - 1] = in_list[2:] graph[u - 1] graph u - 1 u 1 in_list[2:] in_list 2: 2 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 d = [0 for _ in range(n)] d [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 f = [0 for _ in range(n)] f [0 for _ in range(n)] time = 0 time 0 def dfs(now, prev, graph, d, f, time):
    if d[now] != 0:
        return d, f, time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
    return d, f, time dfs if d[now] != 0:
        return d, f, time
     d[now] != 0 d[now] d now 0 return d, f, time return d, f, time d f time time += 1 time 1 d[now] = time d[now] d now time if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
     not graph[now] graph[now] graph now f[now] = time + 1 f[now] f now time + 1 time 1 time += 1 time 1 return d, f, time return d, f, time d f time for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
     k graph[now] graph now if k - 1 == prev or d[k-1] !=0:
            continue
         k - 1 == prev or d[k-1] !=0 k - 1 == prev k - 1 k 1 prev d[k-1] !=0 d[k-1] d k-1 k 1 0 continue _, _, time = dfs(k - 1, now, graph, d, f, time) _ dfs(k - 1, now, graph, d, f, time) dfs k - 1 k 1 now graph d f time _ time time += 1 time 1 f[now] = time f[now] f now time return d, f, time return d, f, time d f time now now prev prev graph graph d d f f time time for i in range(n):
    d, f, time = dfs(i, 0, graph, d, f, time)
    print(i+1, d[i], f[i]) i range(n) range n d, f, time = dfs(i, 0, graph, d, f, time) d dfs(i, 0, graph, d, f, time) dfs i 0 graph d f time f time print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i d = [0 for _ in range(n)] [0 for _ in range(n)] d def dfs(now, prev, graph, d, f, time):
    if d[now] != 0:
        return d, f, time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
    return d, f, time def dfs(now, prev, graph, d, f, time):
    if d[now] != 0:
        return d, f, time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
    return d, f, time dfs d, f, time = dfs(i, 0, graph, d, f, time) dfs(i, 0, graph, d, f, time) d time = dfs(i, 0, graph, d, f, time) dfs(i, 0, graph, d, f, time) time u = in_list[0] in_list[0] u graph = [[] for _ in range(n)] [[] for _ in range(n)] graph time = 0 0 time f, time = dfs(i, 0, graph, d, f, time) dfs(i, 0, graph, d, f, time) f n = int(input()) int(input()) n in_list = list(map(int, input().split())) list(map(int, input().split())) in_list f = [0 for _ in range(n)] [0 for _ in range(n)] f
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
    in_list = list(map(int, input().split()))
    u = in_list[0]
    graph[u - 1] = in_list[2:]

d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 0

def dfs(now, prev, graph, d, f, time):
    if d[now] != 0:
        return d, f, time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return d, f, time
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        _, _, time = dfs(k - 1, now, graph, d, f, time)
    else:
        time += 1
        f[now] = time
    return d, f, time



for i in range(n):
    d, f, time = dfs(i, 0, graph, d, f, time)
    print(i+1, d[i], f[i])

