Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

Python: # -*- coding: utf-8 -*-

def DFS_stack(adj, start):
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n # 0:????¨????, 1:?¨??????????, 2:?¨??????????
    S = []
    time = 1

    S.append(start)
    flag[start] = 1
    d[start] = time
    time = time + 1
    
    while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§
        if len(S) != 0:
            u = S.pop()
            v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] 
            # v := ??£??\???????????????????????¢?´¢??????????????????
            if len(v) != 0:
                S.append(u)
                S.append(v[0])
                flag[v[0]] = 1
                d[v[0]] = time
                time = time + 1
            else:
            #??£??\??????????????¨????¨??????????
                flag[u] = 2
                f[u] = time
                time = time + 1

        else:
        	#??????????????????????????£?????´????????¢?´¢??????????????????????????¢?´¢????§?
            u = flag.index(0)
            S.append(u)
            flag[u] = 1
            d[u] = time
            time = time + 1            

    return d, f    

def DFS(adj, start):
    
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n
    time = 1
    
    def DFS_recursive(u, time):
        #print(u, flag)
        flag[u] = 1
        d[u] = time
        time = time + 1
        v = [i for i, x in enumerate(adj[u]) if x == 1]
        for i in v:
            if flag[i] == 0:
                time = DFS_recursive(i, time)
        flag[u] = 2
        f[u] = time
        time = time + 1
        return time
        
    DFS_recursive(start, time)

    for i in range(n):
        if flag[i] == 0:
            DFS_recursive(i, time)
    
    return d, f



def main():
    
    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1
            
    #d, f = DFS_stack(adj, 0)
    d, f = DFS(adj, 0)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == "__main__":
    main()

Python: import sys
input = lambda: sys.stdin.readline().rstrip()
n=int(input())
s=0 ; st=set() ; ans=[[] for i in range(n)] ; v=0
def dfs(g,v):
    global s,st,ans
    if v in st: return
    else: st.add(v)
    s+=1
    ans[v].append(s)
    for i in g[v]:
        dfs(g,i)
    s+=1
    ans[v].append(s)
g=[]
for _ in range(n):
    a=[int(i)-1 for i in input().split()]
    if a[1]==-1: g.append([])
    else: g.append(a[2:])
for i in range(n):
    if i in st : continue
    else : dfs(g,i)
for i in range(len(ans)):
    print(i+1,*ans[i])

Python: n=0
t=2
def adjacent_matrix():
    global n
    n=int(input())
    v=[]
    array=[]
    for i in range(n):
        zero=[0 for i in range(n)]
        a=list(map(int,input().split()))
        a=a[2:]
        for j in a:
            zero[j-1]=1
        array.append(zero)
    return array
def dfs(array,i,d,f):
    global t
    for (j,x) in enumerate(array[i]):
        if x == 1:
            d[j] = t
            t += 1
            dfs(array,j,d,f)
    f[i] = t
    t += 1
    return 


def main():
    array=adjacent_matrix()
    print()
    d=[1 for i in range(n)]
    f=[1 for i in range(n)]
    dfs(array,0,d,f)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i]))

if __name__ == "__main__":
    main()

Python: time = 0

def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time

n = int(input())

g = {}
s = 0
stack = []
for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]]
    if i == 0:
        s = x[0]

for k, v in g.items():
    if v[1] == 'w':
        dfs_visit(g, v)


for i in range(n):
    node = g[i+1]
    print("{} {} {}".format(i+1, node[2], node[3]))

Python: def depthFirstSearch(i, Adj, d, f, t):
    if d[i - 1]:
        return t

    d[i - 1] = t
    t += 1

    for v in Adj[i - 1]:
        t = depthFirstSearch(v, Adj, d, f, t)

    f[i - 1] = t
    t += 1

    return t


n = int(input())
Adj = [list(map(int, input().split()))[2:] for _ in range(n)]

d = [0] * n
f = [0] * n

t = 1
for i in range(n):
    if d[i] == 0:
        t = depthFirstSearch(i + 1, Adj, d, f, t)

for i, df in enumerate(zip(d, f)):
    print(i + 1, *df)