Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

Python: import abc


class AdjacentGraph:
    """Implementation adjacency-list Graph.
    Beware ids are between 1 and size.
    """
    def __init__(self, size):
        self.size = size
        self._nodes = [[0] * (size+1) for _ in range(size+1)]

    def set_adj_node(self, id_, adj_id):
        self._nodes[id_][adj_id] = 1

    def __iter__(self):
        self._id = 0
        return self

    def __next__(self):
        if self._id < self.size:
            self._id += 1
            return (self._id, self._nodes[self._id][1:])

        raise StopIteration()

    def dfs(self, handler=None):

        visited = []
        while len(visited) < self.size:
            for id_ in range(1, self.size+1):
                if id_ not in visited:
                    stack = [(id_, 0)]
                    break
            while len(stack) > 0:
                i, j = stack.pop()
                if j == 0:
                    if handler:
                        handler.visit(i)
                    visited.append(i)
                    yield i
                try:
                    j = self._nodes[i].index(1, j+1)
                    stack.append((i, j))
                    if j not in visited:
                        stack.append((j, 0))
                except ValueError:
                    if handler:
                        handler.leave(i)


class EventHandler(abc.ABC):
    @abc.abstractmethod
    def visit(self, i):
        pass

    @abc.abstractmethod
    def leave(self, i):
        pass


class Logger(EventHandler):
    def __init__(self, n):
        self.log = [(0, 0)] * n
        self.step = 0

    def visit(self, i):
        self.step += 1
        self.log[i-1] = (self.step, 0)

    def leave(self, i):
        self.step += 1
        (n, m) = self.log[i-1]
        self.log[i-1] = (n, self.step)

    def by_node(self):
        i = 1
        for discover, finish in self.log:
            yield (i, discover, finish)
            i += 1


def run():
    n = int(input())
    g = AdjacentGraph(n)
    log = Logger(n)

    for i in range(n):
        id_, c, *links = [int(x) for x in input().split()]
        for n in links:
            g.set_adj_node(id_, n)

    for i in g.dfs(log):
        pass

    for node in log.by_node():
        print(" ".join([str(i) for i in node]))


if __name__ == '__main__':
    run()

Python: N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)
    is_visited[node_id] = False
    adj_num = int(tmp[1])#各頂点の次元が入っている
    if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = []


d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1

def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1

for node in node_ls:
    dfs(node)

#print(d,f)
for node in node_ls:
    print(node, d[node], f[node])

Python: n = int(input())

class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt)

Nodes = [None] * n
for i in range(n):
    row = [int(tt) for tt in input().split()]
    Nodes[row[0]-1] = Node(row[0], [ row[j + 2] for j in range(row[1])])
        
def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes
Nodes = depthSearch(Nodes)
for node in Nodes:
    print(node)

Python: 
n=int(input())
used=[False for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
mat=[]
for i in range(n):
    tmp=list(map(int,input().split()))
    mat.append(tmp[2:])

t=1
def dfs(now):
    global t
    if used[now]:
        return
    else:
        used[now]=True
    d[now]=t
    t+=1
    for i in range(len(mat[now])):
        dfs(mat[now][i]-1)
    f[now]=t
    t+=1

for i in range(n):
    if used[i]==False:
        dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])

Python: # -*- coding: utf-8 -*-
N = int(input())
adj = [[0]*N for _ in range(N)]
searched = {n: 0 for n in range(N)}
edge = {}

def find_all(list_, x, j=-1):
    return [i for i, n in enumerate(list_) if n==1 and n != j]


for n in range(N):
    inp = list(map(int, input().split()))
    edge[n] = inp[1]
    for i in inp[2:]:
        adj[inp[0]-1][i-1] = 1

time = 1
stack = []
unsearch = set(range(N))
uncomplete = set(range(N))
result = {n:{"found": 0, "finish": 0} for n in range(N)}

while len(unsearch) > 0 or len(stack) > 0:
    if len(stack) == 0:
        i = min(unsearch)
        result[i]["found"] = time
        unsearch.remove(i)
        time += 1

    
    while True:
        j = i
        for n in sorted(unsearch):
            if adj[i][n] == 1:
                j = n
                result[n]["found"] = time
                unsearch.remove(n)
                stack.append(i)
                time += 1
                break

        if i == j:
            result[i]["finish"] = time
    
            if len(stack) != 0:                
                i = stack.pop()
                time += 1
            else:
                break
        else:
            i = j
                
for n in range(N):
    print("{} {} {}".format(n, result[n]["found"], result[n]["finish"]))