N = int(input())
Adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for k in u[2: 2+u[1]]:
            Adj[u[0] - 1][k - 1] = 1
            
            
color = [0] * N #1: visited, 0: not visited, 2: completed
s = [0] * N # start
f = [0] * N # finish

time = 0

def DFS(u):
    global time
    color[u-1] = 1
    time += 1
    s[u-1] = time
    
    for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
    color[u-1] = 2
    time += 1
    f[u-1] = time

for i in range(1, N+1):
    if color[i-1] == 0:
        DFS(i)
        
for i in range(N):
    print('{} {} {}'.format(i+1, s[i], f[i])) N = int(input()) N int(input()) int input() input [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] Adj = [[0 for i in range(N)] for j in range(N)] Adj [[0 for i in range(N)] for j in range(N)] for i in range(N):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for k in u[2: 2+u[1]]:
            Adj[u[0] - 1][k - 1] = 1
            
             i range(N) range N u = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if u[1] > 0:
        for k in u[2: 2+u[1]]:
            Adj[u[0] - 1][k - 1] = 1
            
             u[1] > 0 u[1] u 1 0 for k in u[2: 2+u[1]]:
            Adj[u[0] - 1][k - 1] = 1
            
             k u[2: 2+u[1]] u 2: 2+u[1] 2 2+u[1] 2 u[1] u 1 Adj[u[0] - 1][k - 1] = 1 Adj[u[0] - 1][k - 1] [u[0] - 1] Adj u[0] - 1 u[0] u 0 1 k - 1 k 1 1 color = [0] * N color [0] * N [0] 0 N s = [0] * N s [0] * N [0] 0 N f = [0] * N f [0] * N [0] 0 N time = 0 time 0 def DFS(u):
    global time
    color[u-1] = 1
    time += 1
    s[u-1] = time
    
    for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
    color[u-1] = 2
    time += 1
    f[u-1] = time DFS global time color[u-1] = 1 color[u-1] color u-1 u 1 1 time += 1 time 1 s[u-1] = time s[u-1] s u-1 u 1 time for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
     i range(1, N+1) range 1 N+1 N 1 if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
     Adj[u-1][i-1] == 1 and color[i-1] == 0 Adj[u-1][i-1] == 1 Adj[u-1][i-1] [u-1] Adj u-1 u 1 i-1 i 1 1 color[i-1] == 0 color[i-1] color i-1 i 1 0 DFS(i) DFS i color[u-1] = 2 color[u-1] color u-1 u 1 2 time += 1 time 1 f[u-1] = time f[u-1] f u-1 u 1 time u u for i in range(1, N+1):
    if color[i-1] == 0:
        DFS(i)
         i range(1, N+1) range 1 N+1 N 1 if color[i-1] == 0:
        DFS(i)
         color[i-1] == 0 color[i-1] color i-1 i 1 0 DFS(i) DFS i for i in range(N):
    print('{} {} {}'.format(i+1, s[i], f[i])) i range(N) range N print('{} {} {}'.format(i+1, s[i], f[i])) print '{} {} {}'.format(i+1, s[i], f[i]) '{} {} {}'.format '{} {} {}' format i+1 i 1 s[i] s i f[i] f i u = list(map(int, input().split())) list(map(int, input().split())) u f = [0] * N [0] * N f def DFS(u):
    global time
    color[u-1] = 1
    time += 1
    s[u-1] = time
    
    for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
    color[u-1] = 2
    time += 1
    f[u-1] = time def DFS(u):
    global time
    color[u-1] = 1
    time += 1
    s[u-1] = time
    
    for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
    color[u-1] = 2
    time += 1
    f[u-1] = time DFS color = [0] * N [0] * N color s = [0] * N [0] * N s Adj = [[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] Adj N = int(input()) int(input()) N time = 0 0 time
N = int(input())
Adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for k in u[2: 2+u[1]]:
            Adj[u[0] - 1][k - 1] = 1
            
            
color = [0] * N #1: visited, 0: not visited, 2: completed
s = [0] * N # start
f = [0] * N # finish

time = 0

def DFS(u):
    global time
    color[u-1] = 1
    time += 1
    s[u-1] = time
    
    for i in range(1, N+1):
        if Adj[u-1][i-1] == 1 and color[i-1] == 0:
            DFS(i)
            
    color[u-1] = 2
    time += 1
    f[u-1] = time

for i in range(1, N+1):
    if color[i-1] == 0:
        DFS(i)
        
for i in range(N):
    print('{} {} {}'.format(i+1, s[i], f[i]))