n = int(input())
A = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 1

def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1 

for u in range(n):
    if color[u] == WHITE:
        dfs(u)

for i in range(n):
    print(str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) ) n = int(input()) n int(input()) int input() input [False for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [False for _ in range(n)] A = [[False for _ in range(n)] for _ in range(n)] A [[False for _ in range(n)] for _ in range(n)] for _ in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True _ range(n) range n tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True i range(tmp[1]) range tmp[1] tmp 1 A[tmp[0]-1][tmp[i+2]-1] = True A[tmp[0]-1][tmp[i+2]-1] [tmp[0]-1] A tmp[0]-1 tmp[0] tmp 0 1 tmp[i+2]-1 tmp[i+2] tmp i+2 i 2 1 True WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 WHITE for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) WHITE color = [WHITE for _ in range(n)] color [WHITE for _ in range(n)] 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 = 1 time 1 def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1  dfs global dfs_color, d, f, time color[u] = GRAY color[u] color u GRAY d[u] += time d[u] d u time time += 1 time 1 for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
     v range(n) range n if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
     A[u][v] [u] A u v if color[v] == WHITE:
                dfs(v)
         color[v] == WHITE color[v] color v WHITE dfs(v) dfs v continue color[u] = BLACK color[u] color u BLACK f[u] = time f[u] f u time time += 1 time 1 u u for u in range(n):
    if color[u] == WHITE:
        dfs(u) u range(n) range n if color[u] == WHITE:
        dfs(u) color[u] == WHITE color[u] color u WHITE dfs(u) dfs u for i in range(n):
    print(str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) ) i range(n) range n print(str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) ) print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) str(i+1) + ' ' + str(d[i]) + ' ' str(i+1) + ' ' + str(d[i]) str(i+1) + ' ' str(i+1) str i+1 i 1 ' ' str(d[i]) str d[i] d i ' ' str(f[i]) str f[i] f i color = [WHITE for _ in range(n)] [WHITE for _ in range(n)] color time = 1 1 time WHITE = 0 0 WHITE def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1  def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1  dfs n = int(input()) int(input()) n tmp = list(map(int, input().split())) list(map(int, input().split())) tmp BLACK = 2 2 BLACK d = [0 for _ in range(n)] [0 for _ in range(n)] d GRAY = 1 1 GRAY A = [[False for _ in range(n)] for _ in range(n)] [[False for _ in range(n)] for _ in range(n)] A f = [0 for _ in range(n)] [0 for _ in range(n)] f
n = int(input())
A = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 1

def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1 

for u in range(n):
    if color[u] == WHITE:
        dfs(u)

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