Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

Python: def DPS(graph,vertex,dis_time,fin_time,tmp_time):
    dis_time[vertex]=tmp_time[0]
    for i in range(len(graph[0])):
        if(graph[vertex][i] !=0 and dis_time[i]==0):#枝先の頂点が探索済みでなかったら、
            tmp_time[0]+=1
            DPS(graph,i,dis_time,fin_time,tmp_time)
    
    if(dis_time[vertex]==tmp_time[0]):#vertexから、どの頂点に対しても調査が進まなかったら
        tmp_time[0]+=1
    fin_time[vertex]=tmp_time[0]
    tmp_time[0]+=1



#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
    tmp_ope=list(map(int,input().split()))
    for j in range(tmp_ope[1]):
        graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1


dis_time=[0]*n
fin_time=[0]*n
tmp_time=[1]
for i in range(n):
    if(dis_time[i]==0):
        DPS(graph,i,dis_time,fin_time,tmp_time)

for i in range(n):
    print(f"{i+1} {dis_time[i]} {fin_time[i]}")

Python: cnt = 1
def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
    

n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]

for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
        
for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i)

for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i])

Python: n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
    in_list = list(map(int, input().split()))
    u = in_list[0]
    graph[u - 1] = in_list[2:]

d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 0


def dfs(now, prev, graph, d, f):
    global time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        dfs(k - 1, now, graph, d, f)
    else:
        time += 1
        f[now] = time
    return d, f


d, f = dfs(0, 0, graph, d, f)
for i in range(1, n + 1):
    print(i, d[i - 1], f[i - 1])

Python: from collections import defaultdict as dd

N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
  info = list(map(int, input().split()))
  u.append(info[0])
  graph[info[0]] = info[2:]

def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1

for key in u:
  if seen[key]:
    continue
  dfs(key)

for id in u:
  print("{} {} {}".format(id, d[id], f[id]))

Python: def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1


def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i])

if __name__ == '__main__':
    main()

Python: def d(u):
 global t
 C[u]=1;t+=1;D[u]=t
 for v in range(N):
  if M[u][v]and C[v]==0:d(v)
 C[u]=2;t+=1;F[u]=t
N=int(input())
M=[[0]*N for _ in[0]*N]
for e in[input().split()for _ in[0]*N]:
 for v in e[2:]:M[int(e[0])-1][int(v)-1]=1
C,D,F=[0]*N,[0]*N,[0]*N
t=0
for i in range(N):
 if C[i]==0:d(i)
for i in range(N):print(i+1,D[i],F[i])

Python: # 隣接リスト
n = int(input())

graph = []
for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:
        graph.append([])
    else:
        graph.append(tmp[2:])

#print(graph)
check = [0]*n
count = 0
go = [0]*n
back = [0]*n

def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count

while True:
    if 0 in check:
        k = check.index(0)
        dfs(k)
    else:
        break

#print("check\t:{}".format(check))
#print("go\t:{}".format(go))
#print("back\t:{}".format(back))

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

Python: n = int(input())
g = [[] for _ in range(n+1)] #1-index
for i in range(n):
    u, k, *v = map(int, input().split())
    for j in v:
        g[u].append(j)

#-------------------------------------------
def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#-------------------------------------------
seen = [0]*(n+1) #1-index
seen[0] = 1
seen[1] = 1 
d = [0]*(n+1)
f = [0]*(n+1)
time = 0

dfs(1) #深堀り

for i in range(1,n+1): #孤立点対応
    if seen[i] == 0:
        dfs(i)

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

Python: d_num = int(input())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, input().split())
    graph[u] = neighbors

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited:
        stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave)

Python: import sys, math
from itertools import permutations, combinations, accumulate
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
G = [list(map(int, input().split())) for _ in range(N)]
c = [0]*N # 0:not found, 1:found, 2:finished
res = [[0]*2 for _ in range(N)]

time = 1
def dfs(index):
#    print('index:', index)
    global time
    if c[index]==0:
        c[index]=1
        res[index][0] = time # found
        time += 1
    elif c[index]==1:
        return
    elif c[index]==2:
        return

    u, k, *v = G[index]
    for node in v:
        dfs(node-1) # 1-index -> 0-index

    c[index] = 2
    res[index][1] = time # finished
    time += 1
    return

for i in range(N):
    dfs(i)
res = [[val1]+val2 for val1, val2 in zip(list(range(1, N+1)), res)]
for val in res:
    print(*val)