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: def dfs(G, u, t, d, visited):
  found = t
  visited.add(u)
  t += 1
  for v in G[u]:
    if v not in visited:
      t = dfs(G, v, t, d, visited)
  complete = t
  d[u] = (found, complete)
  t+=1
  return t


n = int(input())
G = {}
for _ in range(n):
  entries = list(map(int, input().split(' ')))
  u = entries[0]
  k = entries[1]
  G[u] = set()
  for v in entries[2:]:
    G[u].add(v)


d = {}
dfs(G, 1, 1, d, set())
for i in sorted(d):
  print(i,d[i][0],d[i][1])

Python: n = int(input())
a = []
for i in range(n):
    a += [list(map(int, input().split()))[2:]]
cnt = 1
pre = [0]*n
aft = [0]*n
color = [0]*n
def dfs(s):
    global cnt
    pre[s-1] = cnt
    cnt += 1
    color[s-1] = 1
    for i in a[s-1]:
        if color[i-1] == 0:dfs(i)
    aft[s-1] = cnt
    cnt += 1

for i in range(n):
    if color[i] == 0:
        dfs(i+1)

for i in range(n):
    print(i+1, pre[i], aft[i])

Python: #coding: utf-8

n = int(input())
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2:2+k]:
        M[u-1][v-1] = True


def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t

t = search(start, t)
for i in range(1,n+1):
    if color[i-1] == "white":
        t = search(i, t)

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

Python: def DPS(graph,vertex,dis_time,fin_time,tmp_time):
    dis_time[vertex]=tmp_time[0]
    for i in range(len(graph[0])):
        if(graph[vertex][i] !=0 and dis_time[i]==0):#枝先の頂点が探索済みでなかったら、
            tmp_time[0]+=1
            DPS(graph,i,dis_time,fin_time,tmp_time)
    
    if(dis_time[vertex]==tmp_time[0]):#vertexから、どの頂点に対しても調査が進まなかったら
        tmp_time[0]+=1
    fin_time[vertex]=tmp_time[0]
    tmp_time[0]+=1



#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
    tmp_ope=list(map(int,input().split()))
    for j in range(tmp_ope[1]):
        graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1


dis_time=[0]*n
fin_time=[0]*n
tmp_time=[1]
for i in range(n):
    if(dis_time[i]==0):
        DPS(graph,i,dis_time,fin_time,tmp_time)

for i in range(n):
    print(f"{i+1} {dis_time[i]} {fin_time[i]}")

Python: cnt = 1
def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
    

n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]

for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
        
for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i)

for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i])

Python: n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
    in_list = list(map(int, input().split()))
    u = in_list[0]
    graph[u - 1] = in_list[2:]

d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 0


def dfs(now, prev, graph, d, f):
    global time
    time += 1
    d[now] = time
    if not graph[now]:
        f[now] = time + 1
        time += 1
        return
    for k in graph[now]:
        if k - 1 == prev or d[k-1] !=0:
            continue
        dfs(k - 1, now, graph, d, f)
    else:
        time += 1
        f[now] = time
    return d, f


d, f = dfs(0, 0, graph, d, f)
for i in range(1, n + 1):
    print(i, d[i - 1], f[i - 1])

Python: from collections import defaultdict as dd

N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
  info = list(map(int, input().split()))
  u.append(info[0])
  graph[info[0]] = info[2:]

def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1

for key in u:
  if seen[key]:
    continue
  dfs(key)

for id in u:
  print("{} {} {}".format(id, d[id], f[id]))

Python: def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1


def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i])

if __name__ == '__main__':
    main()