Go: package main

/*
深さ優先探索
*/

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

Python: N = int(input())

from collections import deque,defaultdict
G = defaultdict(deque)
for i in range(1,N+1):
    t = [int(i) for i in input().split(' ')]
    for j in range(t[1]):
        G[t[0]].append(t[j+2])

time = 1
arrive_time = [-1] * (N + 1) # 到着時刻
finish_time = [-1] * (N + 1) # 到着時刻

def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time

for i in range(1,N+1):
    if arrive_time[i] < 0:
        arrive,finish = dfs(G,i)
        time += 1

for i, (a, f) in enumerate(zip(arrive,finish)):
    if not i == 0:
        print(i,a,f)

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global current_time
global visited,go_time,back_time
global G


def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1


V = int(input())

G = [[] for i in range(V)]

visited = [False]*V

go_time = [0]*V
back_time = [0]*V

for loop in range(V):
    node_id,num,*tmp_adj = list(map(int,input().split()))
    node_id -= 1
    for i in range(num):
        G[node_id].append(tmp_adj[i]-1)

current_time = 1;

for i in range(V):
    if visited[i] == True:
        continue
    visited[i] = True
    dfs(i)

for i in range(V):
    print("%d %d %d"%(i+1,go_time[i],back_time[i]))

Python: n = int(input())
g = []
for i in range(n):
    a = list(map(int,input().split()))
    g.append(a[2:])
d = [0]*n
f = [0]*n
global t
t = 1
d[0] = 1
x = 1
def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t

find(x)
for i in range(n):
    if d[i] == 0:
        t += 1
        d[i] = t
        find(i+1)
for i in range(n):
    print(i+1, d[i], f[i])

Python: def depth(s, time):
    time += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                depth(i, time)
                t = f[i]
    f[s] = time + 1
 
n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [0 for i in range(n+1)]
f = [0 for i in range(n+1)]
 
for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1
 
flag = [0 for i in range(n+1)]
for i in range(1, n+1):
    if flag[i] == 0:
        depth(i, max(f))
 
for i in range(1, n+1):
    print(str(i) + " " + str(d[i]) + " " + str(f[i]))

Python: n = int(input())
adj = [[None for _ in range(n)] for _ in range(n)]
for i in range(n):
    l = list(map(int, input().split()))
    if l[1] == 0:
        continue 
    else:
        for j in range(2,len(l)):
            adj[l[0]-1][l[j]-1] = 1
color = ['white' for _ in range(n)]
d = [None for _ in range(n)]
f = [None for _ in range(n)]
time = 1

def dfs(node):
    global color
    global d 
    global f
    global time 
    S = [node]
    color[node -1] = 'grey'
    d[node -1] = time 
    while S:
        u = S[-1]
        v = 1
        while v <= n:
            if adj[u-1][v-1] == 1 and color[v-1] == 'white':
                break
            v += 1
        if v < n+1:
            color[v-1] = 'grey'
            time += 1
            d[v-1] = time 
            S.append(v)
        else:
            time += 1
            S.pop()
            color[u-1] = ['black']
            f[u-1] = time

for node in range(1, n+1):
    if color[node-1] == 'white':
        dfs(node)
        time += 1
for i in range(n):
    print(' '.join([str(i+1), str(d[i]), str(f[i])]))

Python: ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return

n = ii()
t = tree(n)

for i in range(n):
    vk = li()
    u = vk[0]
    k = vk[1]
    v = vk[2:]
    t.add(u-1,v)

for i in range(n):
    t.search(i)

for i in range(n):
    print(i+1, t.start[i], t.finish[i])