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
timestamp = 1

stack = []
indata = []
visit = []      #?¨?????¨????
visitTime = []  #?¨???????????¨??????¨
lastTimeStack = []      #?¨?????????????????¨??????¨


def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v)

def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1

"""
main
"""
inputdata()
stack.append(0)             #?????????????´????push??????

while True:
    if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

    n = stack.pop()         #??????????????????pop??????
    procV(n)                #pop????????????????????????????????????

    #???????????¢???
    for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i)

i = 1
for val in visitTime:
    li = [i, val[0], val[1]]
    print(' '.join(map(str, li)))
    i += 1

Python: j = 1

def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j

n = int(input())
g = [[]]
r = [[i,0,0] for i in range(n + 1)]
v = []

for i in range(n):
    g.append(list(map(int, input().split())))


for i in range(1, n + 1):
    if i in v:
        continue
    dfs(g,i,r,v)

for i in range(1,n+1):
    print(*r[i])

Python: def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1


n = int(input())

adjMat = [[0] * n for _ in range(n)]
color = ['white'] * n
arrive = [0] * n
finish = [0] * n
time = 1

for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1

for root in range(n):
    if color[root] == 'white':
        dfs(root)


for i in range(n):
    out = ''
    out += '{} {} {}'.format(i + 1, arrive[i], finish[i])
    print(out)

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]))