from collections import defaultdict

def dfs(edges, n, d, f, time):
    if n in d:
        return
    time[0] += 1
    d[n] = time[0]
    for to in edges[n]:
        dfs(edges, to, d, f, time)
    time[0] += 1
    f[n] = time[0]

N = int(input())

edges = defaultdict(list)

for _ in range(N):
    l = list(map(int, input().split()))
    fr = l[0]
    degree = l[1]
    edges[fr] = l[2:]

d = {} # discover time                                                                                                                                                                                      
f = {} # finish time                                                                                                                                                                                        

time = [0]
for n in range(1, N+1):
    dfs(edges, n, d, f, time)

for n in range(1, N+1):
    print('%d %d %d' % (n, d[n], f[n]))



 from collections import defaultdict def dfs(edges, n, d, f, time):
    if n in d:
        return
    time[0] += 1
    d[n] = time[0]
    for to in edges[n]:
        dfs(edges, to, d, f, time)
    time[0] += 1
    f[n] = time[0] dfs if n in d:
        return
     n in d n d return time[0] += 1 time[0] time 0 1 d[n] = time[0] d[n] d n time[0] time 0 for to in edges[n]:
        dfs(edges, to, d, f, time)
     to edges[n] edges n dfs(edges, to, d, f, time) dfs edges to d f time time[0] += 1 time[0] time 0 1 f[n] = time[0] f[n] f n time[0] time 0 edges edges n n d d f f time time N = int(input()) N int(input()) int input() input edges = defaultdict(list) edges defaultdict(list) defaultdict list for _ in range(N):
    l = list(map(int, input().split()))
    fr = l[0]
    degree = l[1]
    edges[fr] = l[2:] _ range(N) range N l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split fr = l[0] fr l[0] l 0 degree = l[1] degree l[1] l 1 edges[fr] = l[2:] edges[fr] edges fr l[2:] l 2: 2 d = {} d {} f = {} f {} time = [0] time [0] 0 for n in range(1, N+1):
    dfs(edges, n, d, f, time) n range(1, N+1) range 1 N+1 N 1 dfs(edges, n, d, f, time) dfs edges n d f time for n in range(1, N+1):
    print('%d %d %d' % (n, d[n], f[n])) n range(1, N+1) range 1 N+1 N 1 print('%d %d %d' % (n, d[n], f[n])) print '%d %d %d' % (n, d[n], f[n]) '%d %d %d' (n, d[n], f[n]) n d[n] d n f[n] f n f = {} {} f time = [0] [0] time N = int(input()) int(input()) N l = list(map(int, input().split())) list(map(int, input().split())) l fr = l[0] l[0] fr degree = l[1] l[1] degree d = {} {} d edges = defaultdict(list) defaultdict(list) edges def dfs(edges, n, d, f, time):
    if n in d:
        return
    time[0] += 1
    d[n] = time[0]
    for to in edges[n]:
        dfs(edges, to, d, f, time)
    time[0] += 1
    f[n] = time[0] def dfs(edges, n, d, f, time):
    if n in d:
        return
    time[0] += 1
    d[n] = time[0]
    for to in edges[n]:
        dfs(edges, to, d, f, time)
    time[0] += 1
    f[n] = time[0] dfs
from collections import defaultdict

def dfs(edges, n, d, f, time):
    if n in d:
        return
    time[0] += 1
    d[n] = time[0]
    for to in edges[n]:
        dfs(edges, to, d, f, time)
    time[0] += 1
    f[n] = time[0]

N = int(input())

edges = defaultdict(list)

for _ in range(N):
    l = list(map(int, input().split()))
    fr = l[0]
    degree = l[1]
    edges[fr] = l[2:]

d = {} # discover time                                                                                                                                                                                      
f = {} # finish time                                                                                                                                                                                        

time = [0]
for n in range(1, N+1):
    dfs(edges, n, d, f, time)

for n in range(1, N+1):
    print('%d %d %d' % (n, d[n], f[n]))




