Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

Python: n = int(input())
d = [0]*(n+1)
f = [0]*(n+1)
t = 1

adjacent_list = [[] for _ in range(n+1)]
for i in range(n):
    e = list(map(int,input().split()))
    if e[1] != 0:
        adjacent_list[i+1].extend(e[2:])
#print(adjacent_list)

def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1

for v in range(1,n+1):
    dfs(v)

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

Python: def DFS(adj, start):
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n
    S = []
    time = 1

    S.append(start)
    flag[start] = 1
    d[start] = time
    time = time + 1
    
    while len(S) != 0:
        u = S.pop()
        v = next(adj, u)
        v = [i for i in v if 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

    return d, f

def next(adj, u):
    """
    u?????£??\??????????????????????????????????????????
    """
    return [i for i, x in enumerate(adj[u]) if x == 1]
    

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(adj, 0)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == "__main__":
    main()

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

WHITE = 0
GRAY = 1
BLACK = 2


def dbg_record(records):
    for index, record in enumerate(records):
        print("???????????????: %d" % index)
        if isinstance(record, dict):
            print("??\??????: %d" % record.get("visit", -1))
            print("?????????: %d" % record.get("leave", -1))
        else:
            print("?????????")
        print("")


def dfs(matrix):
    def internal_dfs(node_id, current_time):
        if state[node_id] == WHITE:
            # ?¨??????????
            state[node_id] = GRAY
            stack.append(node_id)
            records[node_id] = {"visit": current_time}  # ?¨??????????????¨????

            # ?¬?????¨????????????¨?????§????????????????????¢???
            next_id = None
            for index in range(len(matrix)):
                if matrix[node_id][index] == 1 and state[index] == WHITE:
                    next_id = index
                    break

            if next_id is not None:
                return internal_dfs(next_id, current_time + 1)
            elif 0 < len(stack):
                # ?¬?????¨????????????¨?????§?????????????????????????????????????????°?????????
                return internal_dfs(stack.pop(), current_time + 1)
        elif state[node_id] == GRAY:
            # ????????????

            # ?¬?????¨????????????¨?????§????????????????????¢???
            next_id = None
            for index in range(len(matrix)):
                if matrix[node_id][index] == 1 and state[index] == WHITE:
                    next_id = index
                    break

            if next_id is not None:
                stack.append(node_id)
                return internal_dfs(next_id, current_time)
            elif 0 < len(stack):
                # ?¬?????¨????????????¨?????§?????????????????????????????????????????°?????????
                state[node_id] = BLACK
                records[node_id]["leave"] = current_time  # ????????????????¨????
                return internal_dfs(stack.pop(), current_time + 1)
            else:  # ??????????§????????????£???????????¨??? (node_id should be 0)
                state[node_id] = BLACK
                records[node_id]["leave"] = current_time
                return current_time
        elif state[node_id] == BLACK:
            print("Black!!")

    state = [WHITE] * len(matrix)  # White, Gray, Black
    records = [None] * len(matrix)  # Save time when the node is processed
    stack = []
    current_time = 0

    while True:
        node_id = None
        for index, record in enumerate(records):
            if record is None:
                node_id = index
                break

        if node_id is None:
            break
        else:
            current_time = internal_dfs(node_id, current_time + 1)

    return records


if __name__ == "__main__":
    # ??????????????????
    # lines = [
    #     "6",
    #     "1 2 2 3",
    #     "2 2 3 4",
    #     "3 1 5",
    #     "4 1 6",
    #     "5 1 6",
    #     "6 0",
    # ]
    lines = sys.stdin.readlines()

    # Create n * n matrix
    dimension = int(lines[0])
    matrix = []
    for x in range(dimension):
        matrix.append([0] * dimension)

    # Set edge info
    for index, line in enumerate(lines[1:]):
        for edge in [int(x) for x in line.strip().split(" ")[2:]]:
            matrix[index][edge - 1] = 1

    records = dfs(matrix)
    for index, line in enumerate(records):
        if line is not None:
            print("%d %d %d" % (index + 1, line.get("visit", -1), line.get("leave", -1)))
        else:
            print("%d None None" % (index + 1))

Python: n = int(input())
g = [[]for i in range(n)]
for i in range(n):
    v = list(map(int,input().split()))
    u = v[0]-1
    k = v[1]
    for j in range(k):
        g[u].append(v[j+2]-1)
time = 1
ans = []
d = [0]*n
f = [0] *n
visited = [0]*n

def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
    
for i in range(n):
    if not visited[i]:dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])