Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

Python: from collections import deque


N = 100
WHITE = 0
GRAY = 1
BLACK = 2

M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0


def main():
    n = int(input())
    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    dfs(n)

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


def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u)


def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt


if __name__ == '__main__':
    main()

Python: def dfs(u):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(1, n+1):
        if data[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs(v)
    color[u] = 'Black'
    time += 1
    f[u] = time


n = int(input())
A = [list(map(int, input().split()))for _ in range(n)]
data = [[0]*(n+1) for _ in range(n+1)]
color = ['White']*(n+1)
d = [None]*(n+1)
f = [None]*(n+1)
time = 0
for i in A:
    for j in i[2:]:
        data[i[0]][j] = 1

for u in range(1, n+1):
    if color[u] == 'White':
        dfs(u)
for i in range(1, n+1):
    print('{} {} {}'.format(i, d[i], f[i]))

Python: from enum import Enum

class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2

def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time



def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time)

N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

colors = [Color.WHITE for i in range(N)]
stack = []
total_time = 0
d = [0 for i in range(N)]
f = [0 for i in range(N)]

dfs(total_time)

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

Python: # -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1

def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
    
def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


    
if __name__ == '__main__':
    main()

Python: cin = open(0).read().strip().split('\n')
n = int(cin[0])
g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]]

first_order = [-1] * n
last_order = [-1] * n
ptr = 1

def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1

seen = [False] * n
dfs(g, seen, 0)

# 孤立している頂点対策
for i in range(n):
    if not seen[i]:
        ans = dfs(g, seen, i)

# 出力
for idx, (f, l) in enumerate(zip(first_order, last_order)):
    print(idx+1, f, l)

Python: global t
t = 0

class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib

def dfs(G, d, f, now): #now:1,2,...
    print("now:",now)
    global t
    t += 1
    print("t:",t)
    if f[now-1] != 0: t -= 1
    else:
        d[now-1] = t
        print("d:",d)
        print("f:",f)
        for i in G[now-1].neib:
            print("i:",i)
            if i != -1:
                print("next")
                dfs(G, d, f, i)
            else:
                print("end of branch")
            
        t += 1
        if f[now-1] == 0:
            f[now-1] = t

        print("f:",f)


dnum = int(input()) #頂点数
N = []
for i in range(dnum):
    data = input().split()
    
    u = int(data[0])
    k = int(data[1])
    if k > 0:
        v = list(map(int, data[2:]))
    else:
        v = [-1]

    node = Node(u,k,v)
    N.append(node)

d = [0]*dnum #find time
f = [0]*dnum #finish time

dfs(N, d, f, 1)

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