from collections import deque
q = deque()

n = int(input())
C = [deque() for _ in range(n+1)]

for i in range(n):
    tmp = list(map(int,input().split()))
    for j in range(tmp[1]):
        C[tmp[0]].append(tmp[2+j])

visited = [False]*(n+1)
d = [0]*(n+1)
f = [0]*(n+1)
t = 0

def stack(i):
    global t
    if visited[i] == False:
        q.append(i)
    while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t

for i in range(1,n+1):
    stack(i)

for i in range(1,n+1):
    print("{} {} {}".format(i,d[i],f[i])) from collections import deque q = deque() q deque() deque n = int(input()) n int(input()) int input() input deque() for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) deque() deque C = [deque() for _ in range(n+1)] C [deque() for _ in range(n+1)] for i in range(n):
    tmp = list(map(int,input().split()))
    for j in range(tmp[1]):
        C[tmp[0]].append(tmp[2+j]) i 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 j in range(tmp[1]):
        C[tmp[0]].append(tmp[2+j]) j range(tmp[1]) range tmp[1] tmp 1 C[tmp[0]].append(tmp[2+j]) [tmp[0]].append [tmp[0]] C tmp[0] tmp 0 append tmp[2+j] tmp 2+j 2 j visited = [False]*(n+1) visited [False]*(n+1) [False] False n+1 n 1 d = [0]*(n+1) d [0]*(n+1) [0] 0 n+1 n 1 f = [0]*(n+1) f [0]*(n+1) [0] 0 n+1 n 1 t = 0 t 0 def stack(i):
    global t
    if visited[i] == False:
        q.append(i)
    while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t stack global t if visited[i] == False:
        q.append(i)
     visited[i] == False visited[i] visited i False q.append(i) q.append q append i while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t q node = q[-1] node q[-1] q -1 if d[node] == 0:
            t += 1
            d[node] = t
         d[node] == 0 d[node] d node 0 t += 1 t 1 d[node] = t d[node] d node t visited[node] = True visited[node] visited node True for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t _ range(len(C[node])) range len(C[node]) len C[node] C node tmp = C[node].popleft() tmp C[node].popleft() [node].popleft [node] C node popleft if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
         visited[tmp] == False visited[tmp] visited tmp False next_node = tmp next_node tmp q.append(next_node) q.append q append next_node break t += 1 t 1 f[q.pop()] = t f[q.pop()] f q.pop() q.pop q pop t i i for i in range(1,n+1):
    stack(i) i range(1,n+1) range 1 n+1 n 1 stack(i) stack i for i in range(1,n+1):
    print("{} {} {}".format(i,d[i],f[i])) i range(1,n+1) range 1 n+1 n 1 print("{} {} {}".format(i,d[i],f[i])) print "{} {} {}".format(i,d[i],f[i]) "{} {} {}".format "{} {} {}" format i d[i] d i f[i] f i n = int(input()) int(input()) n visited = [False]*(n+1) [False]*(n+1) visited q = deque() deque() q tmp = list(map(int,input().split())) list(map(int,input().split())) tmp C = [deque() for _ in range(n+1)] [deque() for _ in range(n+1)] C f = [0]*(n+1) [0]*(n+1) f d = [0]*(n+1) [0]*(n+1) d def stack(i):
    global t
    if visited[i] == False:
        q.append(i)
    while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t def stack(i):
    global t
    if visited[i] == False:
        q.append(i)
    while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t stack t = 0 0 t
from collections import deque
q = deque()

n = int(input())
C = [deque() for _ in range(n+1)]

for i in range(n):
    tmp = list(map(int,input().split()))
    for j in range(tmp[1]):
        C[tmp[0]].append(tmp[2+j])

visited = [False]*(n+1)
d = [0]*(n+1)
f = [0]*(n+1)
t = 0

def stack(i):
    global t
    if visited[i] == False:
        q.append(i)
    while q:
        #ノードの探索開始
        node = q[-1]
        if d[node] == 0:
            t += 1
            d[node] = t
        visited[node] = True
        for _ in range(len(C[node])):
            tmp = C[node].popleft()
            if visited[tmp] == False:
                next_node = tmp
                q.append(next_node)    #未探索の接続ノード
                break
        
        #未探索接続ノードがなければそのノードは探索終了
        else:
            t += 1
            f[q.pop()] = t

for i in range(1,n+1):
    stack(i)

for i in range(1,n+1):
    print("{} {} {}".format(i,d[i],f[i]))
