Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

Python: def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1

if __name__ == '__main__':

	n = int(input())
	
	G = [[] for _ in range(n+1)] 
	F = [0 for _ in range(n+1)]
	L = [0 for _ in range(n+1)]

	#深さ優先探索
	#探索済配列
	seen = [False for _ in range(n+1)]

	for i in range(n):
		cmd = list(map(int,input().split()))
		m = cmd[1]
		if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	ptr = 1
	for i in range(1,n):
		if seen[i] == False :
			dfs(G,i)

	for i in range(1,n+1):
		print(i,F[i],L[i])

Python: n=int(input())

l=[[0 for i in range(n)] for j in range(n)]##静的確保 隣接行列
d=[0 for i in range(n)]##発見
f=[0 for i in range(n)]##完了
stack=[]##スタック
check=[]

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1
##print("---隣接行列---")
##print(l)

time=1
d[0]=1
stack+=[1]
check+=[-1]

while len(stack)!=0:
    ##print("----------while---------")
    for i in range(n):
        if l[stack[-1]-1][i]==1 and not i+1 in check:
            time+=1
            d[i]=time
            stack+=[i+1]

           ## print("stack:",stack)
           ## print("d[",i,"]:",d[i])
            break
        elif i==n-1:
##最深    
            check+=[stack[-1]]
            time+=1
            f[stack.pop()-1]=time

            ##print("f[",i,"]:",f[i])
            ##print("check:",check)
            


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

Python: class Node():
    def __init__(self, v):
        self.d = 0
        self.f = 0
        self.v = v

    def __repr__(self):
        return "Node({},{},{})".format(
            self.d, self.f, self.v)


def read_node():
    n = int(input())
    adj_list = [[] for _ in range(n + 1)]

    for _ in range(n):
        id, _, *v = [int(x) for x in input().split()]
        adj_list[id] = Node(v)

    return adj_list


def depth_first_search(adj_list):
    def dfs(id):
        nonlocal adj_list, timestamp

        adj_list[id].d = timestamp
        for adj_id in adj_list[id].v:
            if adj_list[adj_id].d == 0:
                timestamp += 1
                dfs(adj_id)
        timestamp += 1
        adj_list[id].f = timestamp

    timestamp = 1
    for id in range(1, len(adj_list)):
        if adj_list[id].d == 0:
            dfs(id)
            timestamp += 1


def print_result(adj_list):
    for id in range(1, len(adj_list)):
        print(id, adj_list[id].d, adj_list[id].f)


def main():
    adj_list = read_node()
    depth_first_search(adj_list)
    print_result(adj_list)


if __name__ == '__main__':
    main()

Python: n = int(input())
adjacency_list = []
for i in range(n):
    input_list = list(map(int, input().split()))
    adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
    if i not in checked_set:
        dfs_stack = []
        dfs_stack.append(i)
        while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1
for i in range(n):
    print(f'{i+1} {v[i]} {f[i]}')

Python: 
WHITE = 0
GRAY = 1
BLACK = 2

NIL = -1


def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time


def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
            


n = int(input())

m = [[0 for i in range(n + 1)] for j in range(n + 1)]
vid = [0] * n
d = [0] * n
f = [0] * n
S = []
color = [WHITE] * n
time = 0
nt = [0] * n

tmp = []
for i in range(n):
    nums=list(map(int,input().split()))
    tmp.append(nums)
    vid[i] = nums[0]

for i in range(n):
    for j in range(tmp[i][1]):
        m[i][vid.index(tmp[i][j + 2])] = 1

for i in range(n):
    if color[i] == WHITE:
        dfs(i)

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

Python: # input
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v_list = list(map(int, input().split()))
    for v in v_list:
        A[u-1][v-1] = 1

# init
d = [0] * n
f = [0] * n
t = 0

# recursive
def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs
for i in range(n):
    if d[i] == 0:
        dfs(i)

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