import sys
sys.setrecursionlimit(10**9)
from collections import deque

n = int(input())
u = [[] for i in range(n+1)] #隣接リスト
for i in range(n):
    v = list(map(int, input().split()))
    u[v[0]] = v[1:] #v = [次数, 頂点...]

d = [-1] * (n+1)
f = [-1] * (n+1)
visited = [False] * (n+1)
visited[0] = True
time = 1

#再帰
def dfs(c):
    global time
    d[c] = time
    time += 1
    visited[c] = True
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
    f[c] = time
    time += 1
"""
探索は元の始点から到達可能なすべての頂点を発見するまで続き、
未発見の頂点が残っていれば、
その中の番号が一番小さい１つを新たな始点として探索を続けます。
"""
while False in visited:
    dfs(visited.index(False))

for i in range(1, n+1):
    print(i, d[i], f[i]) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 from collections import deque n = int(input()) n int(input()) int input() input [] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [] u = [[] for i in range(n+1)] u [[] for i in range(n+1)] for i in range(n):
    v = list(map(int, input().split()))
    u[v[0]] = v[1:] #v = [次数, 頂点...] i range(n) range n v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u[v[0]] = v[1:] u[v[0]] u v[0] v 0 v[1:] v 1: 1 d = [-1] * (n+1) d [-1] * (n+1) [-1] -1 n+1 n 1 f = [-1] * (n+1) f [-1] * (n+1) [-1] -1 n+1 n 1 visited = [False] * (n+1) visited [False] * (n+1) [False] False n+1 n 1 visited[0] = True visited[0] visited 0 True time = 1 time 1 def dfs(c):
    global time
    d[c] = time
    time += 1
    visited[c] = True
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
    f[c] = time
    time += 1 dfs global time d[c] = time d[c] d c time time += 1 time 1 visited[c] = True visited[c] visited c True for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
     i range(1, u[c][0]+1) range 1 u[c][0]+1 u[c][0] [c] u c 0 1 if not visited[u[c][i]]:
            dfs(u[c][i])
     not visited[u[c][i]] visited[u[c][i]] visited u[c][i] [c] u c i dfs(u[c][i]) dfs u[c][i] [c] u c i f[c] = time f[c] f c time time += 1 time 1 c c """
探索は元の始点から到達可能なすべての頂点を発見するまで続き、
未発見の頂点が残っていれば、
その中の番号が一番小さい１つを新たな始点として探索を続けます。
""" while False in visited:
    dfs(visited.index(False)) False in visited False visited dfs(visited.index(False)) dfs visited.index(False) visited.index visited index False for i in range(1, n+1):
    print(i, d[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i d = [-1] * (n+1) [-1] * (n+1) d def dfs(c):
    global time
    d[c] = time
    time += 1
    visited[c] = True
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
    f[c] = time
    time += 1 def dfs(c):
    global time
    d[c] = time
    time += 1
    visited[c] = True
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
    f[c] = time
    time += 1 dfs u = [[] for i in range(n+1)] [[] for i in range(n+1)] u v = list(map(int, input().split())) list(map(int, input().split())) v visited = [False] * (n+1) [False] * (n+1) visited n = int(input()) int(input()) n time = 1 1 time f = [-1] * (n+1) [-1] * (n+1) f
import sys
sys.setrecursionlimit(10**9)
from collections import deque

n = int(input())
u = [[] for i in range(n+1)] #隣接リスト
for i in range(n):
    v = list(map(int, input().split()))
    u[v[0]] = v[1:] #v = [次数, 頂点...]

d = [-1] * (n+1)
f = [-1] * (n+1)
visited = [False] * (n+1)
visited[0] = True
time = 1

#再帰
def dfs(c):
    global time
    d[c] = time
    time += 1
    visited[c] = True
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            dfs(u[c][i])
    f[c] = time
    time += 1
"""
探索は元の始点から到達可能なすべての頂点を発見するまで続き、
未発見の頂点が残っていれば、
その中の番号が一番小さい１つを新たな始点として探索を続けます。
"""
while False in visited:
    dfs(visited.index(False))

for i in range(1, n+1):
    print(i, d[i], f[i])
