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: import sys
input = sys.stdin.readline
v = []
tl = []
t = 1

def rec(node):
	global t, tl, v
	if tl[node-1][0] != -1:
		# print("ret", node, tl[node-1][0])
		return
	tl[node-1][0] = t
	t += 1
	# print("t: {}", t)
	adj = v[node-1][2:]
	# print("adj: ", adj)
	for i in adj:
		rec(v[i-1][0])
	tl[node-1][1] = t
	t += 1

def main():
	global v, tl
	n = int(input().strip())
	tl = [[-1, -1] for _ in range(n)]
	for i in range(n):
		l = list(map(int, input().strip().split()))
		v.append(l)
	for i in range(1, n+1):
		rec(i)
	for i in range(n):
		print("{} {} {}".format(i+1, tl[i][0], tl[i][1]))

if __name__ == '__main__':
	main()

Python: 
def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time


def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


n = int(input())

M = [[0 for i in range(n)] for j in range(n)]
color = ['WHITE'] * n  # 各頂点の色を記録。ホワイト（未探索）、グレイ（探索中）、ブラック（探索ずみ）
d = [None] * n  # vを最初に発見した時間
f = [None] * n  # vの完了時刻
time = 0

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row)))

dfs()

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

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

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg)

d = [-1] * n
f = [-1] * n

t = 0
d[0] = t

# recursive


def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
            


for i in range(n):
    if d[i-1] == -1:
        dfs(i-1)


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

Python: n = int(input())
d = [0]*n
f = [0]*n
G = [[] for _ in range(n)]
for _ in range(n):
    l = list(map(int, input().split()))
    u, k = l[:2]
    l = list(map(lambda x: x-1, l[2:]))
    G[u-1] = l

timestamp = [i+1 for i in range(2*n)]
def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True
for i in range(n):
    dfs(i)
    
for i in range(n):
    print(i+1, d[i], f[i])

Python: def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t

def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k)

if __name__ == '__main__':
    main()

Python: n=int(input())
adj=[None]
for i in range(n):
    adj_i=list(map(int,input().split()[2:]))
    adj.append(adj_i)
sndf=[None]
for i in range(1,n+1):
    sndf.append([False,i])
path=[]
time=0
def dfs(u):
    global time
    sndf[u][0]=True
    time+=1
    sndf[u].append(time)
    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    time+=1
    sndf[u].append(time)
for i in range(1,n+1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:])

Python: n=int(input())
d=[0 for _ in range(n+1)]
f=[0 for _ in range(n+1)]
G=[]
G.append([])
for i in range(n):
    u,k,*v=map(int,input().split())
    G.append(v)

checked=[False for _ in range(n+1)]
timestamp=1

def dfs(id):
    global timestamp
    d[id]=timestamp
    checked[id]=True
    timestamp+=1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id]=timestamp
    timestamp+=1

for id in range(1,n+1):
    if not checked[id]:
        dfs(id)

for i in range(1,n+1):
    print("{0} {1} {2}".format(i,d[i],f[i]))