# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(100000)
N = int(input())
adj = [[0]*N for _ in range(N)]
searched = {n: 0 for n in range(N)}
edge = {}

for n in range(N):
    inp = list(map(int, input().split()))
    edge[n] = inp[1]
    for i in inp[2:]:
        adj[inp[0]-1][i-1] = 1

time = 1
stack = []
unsearch = set(range(N))
uncomplete = set(range(N))
result = {n:{"found": 0, "finish": 0} for n in range(N)}

def DFS(i):
    global time
    global unsearch
    
    itr = sorted(unsearch)
    
    for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
    result[i]["finish"] = time
    time += 1
    
while len(unsearch):
    i = min(unsearch)
    unsearch.remove(i)
    result[i]["found"] = time
    time += 1
    DFS(i)

for n in range(N):
    print("{} {} {}".format(n+1, result[n]["found"], result[n]["finish"]))  import sys sys sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 N = int(input()) N int(input()) int input() input [0]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0]*N [0] 0 N adj = [[0]*N for _ in range(N)] adj [[0]*N for _ in range(N)] n: 0 for n in range(N) for n in range(N) n range(N) range N for n in range(N) n 0 searched = {n: 0 for n in range(N)} searched {n: 0 for n in range(N)} edge = {} edge {} for n in range(N):
    inp = list(map(int, input().split()))
    edge[n] = inp[1]
    for i in inp[2:]:
        adj[inp[0]-1][i-1] = 1 n range(N) range N inp = list(map(int, input().split())) inp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split edge[n] = inp[1] edge[n] edge n inp[1] inp 1 for i in inp[2:]:
        adj[inp[0]-1][i-1] = 1 i inp[2:] inp 2: 2 adj[inp[0]-1][i-1] = 1 adj[inp[0]-1][i-1] [inp[0]-1] adj inp[0]-1 inp[0] inp 0 1 i-1 i 1 1 time = 1 time 1 stack = [] stack [] unsearch = set(range(N)) unsearch set(range(N)) set range(N) range N uncomplete = set(range(N)) uncomplete set(range(N)) set range(N) range N n:{"found": 0, "finish": 0} for n in range(N) for n in range(N) n range(N) range N for n in range(N) n {"found": 0, "finish": 0} "found" "found" 0 "finish" "finish" 0 result = {n:{"found": 0, "finish": 0} for n in range(N)} result {n:{"found": 0, "finish": 0} for n in range(N)} def DFS(i):
    global time
    global unsearch
    
    itr = sorted(unsearch)
    
    for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
    result[i]["finish"] = time
    time += 1
     DFS global time global unsearch itr = sorted(unsearch) itr sorted(unsearch) sorted unsearch for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
     j itr if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
     adj[i][j] == 1 and j in unsearch adj[i][j] == 1 adj[i][j] [i] adj i j 1 j in unsearch j unsearch result[j]["found"] = time result[j]["found"] [j] result j "found" time time += 1 time 1 unsearch.remove(j) unsearch.remove unsearch remove j DFS(j) DFS j result[i]["finish"] = time result[i]["finish"] [i] result i "finish" time time += 1 time 1 i i while len(unsearch):
    i = min(unsearch)
    unsearch.remove(i)
    result[i]["found"] = time
    time += 1
    DFS(i) len(unsearch) len unsearch i = min(unsearch) i min(unsearch) min unsearch unsearch.remove(i) unsearch.remove unsearch remove i result[i]["found"] = time result[i]["found"] [i] result i "found" time time += 1 time 1 DFS(i) DFS i for n in range(N):
    print("{} {} {}".format(n+1, result[n]["found"], result[n]["finish"]))  n range(N) range N print("{} {} {}".format(n+1, result[n]["found"], result[n]["finish"])) print "{} {} {}".format(n+1, result[n]["found"], result[n]["finish"]) "{} {} {}".format "{} {} {}" format n+1 n 1 result[n]["found"] [n] result n "found" result[n]["finish"] [n] result n "finish" edge = {} {} edge time += 1 1 time def DFS(i):
    global time
    global unsearch
    
    itr = sorted(unsearch)
    
    for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
    result[i]["finish"] = time
    time += 1
     def DFS(i):
    global time
    global unsearch
    
    itr = sorted(unsearch)
    
    for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
    result[i]["finish"] = time
    time += 1
     DFS N = int(input()) int(input()) N uncomplete = set(range(N)) set(range(N)) uncomplete unsearch = set(range(N)) set(range(N)) unsearch result = {n:{"found": 0, "finish": 0} for n in range(N)} {n:{"found": 0, "finish": 0} for n in range(N)} result searched = {n: 0 for n in range(N)} {n: 0 for n in range(N)} searched inp = list(map(int, input().split())) list(map(int, input().split())) inp adj = [[0]*N for _ in range(N)] [[0]*N for _ in range(N)] adj stack = [] [] stack i = min(unsearch) min(unsearch) i time = 1 1 time
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(100000)
N = int(input())
adj = [[0]*N for _ in range(N)]
searched = {n: 0 for n in range(N)}
edge = {}

for n in range(N):
    inp = list(map(int, input().split()))
    edge[n] = inp[1]
    for i in inp[2:]:
        adj[inp[0]-1][i-1] = 1

time = 1
stack = []
unsearch = set(range(N))
uncomplete = set(range(N))
result = {n:{"found": 0, "finish": 0} for n in range(N)}

def DFS(i):
    global time
    global unsearch
    
    itr = sorted(unsearch)
    
    for j in itr:
        if adj[i][j] == 1 and j in unsearch:
            result[j]["found"] = time
            time += 1
            unsearch.remove(j)
            DFS(j)
    result[i]["finish"] = time
    time += 1
    
while len(unsearch):
    i = min(unsearch)
    unsearch.remove(i)
    result[i]["found"] = time
    time += 1
    DFS(i)

for n in range(N):
    print("{} {} {}".format(n+1, result[n]["found"], result[n]["finish"])) 