Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

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

Python: n = int(input())
g = [None] * n
visited = [0] * n
root = set(range(n))
ts = [[0, 0] for _ in range(n)]
t = 1

while n:
    l = list(map(int, input().split()))
    connected = [i - 1 for i in l[2:]]
    g[l[0] - 1] = [i - 1 for i in l[2:]]
    root -= set(connected)
    n -= 1


def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            t += 1
            dfs(c)
    t += 1
    lts[1] = t


for r in sorted(root):
    dfs(r)

for i, v in enumerate(ts):
    print(i + 1, *v)

Python: #16D8101014F KurumeRyunosuke 2018/6/20

n=int(input())
ls=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
	tmp=input().split()
	for j in range(int(tmp[1])):
		ls[i][int(tmp[j+2])-1]=1

"""
for i in range(n):
    for j in range(n):
        if(j!=n-1):
            print(int(ls[i][j]), end=' ')
        else:
            print(int(ls[i][j]))
"""
stuck=[0]
count=1
d=[0 for i in range(n)]
f=[0 for i in range(n)]
d[0]=count
while True:
	count+=1
	p=0
	for i in range(n):
		if ls[stuck[len(stuck)-1]][i] is not 0:
			ls[stuck[len(stuck)-1]][i]=0
			
			p=1
			#print(stuck)
			stuck.append(i)
			d[stuck[len(stuck)-1]]=count
			break
	if p is 1:
		for i in range(n):
			ls[i][stuck[len(stuck)-1]]=0

	if p is 0:
		#print("//")
		a=stuck.pop()
		f[a]=count
		for i in range(n):
			ls[a][i]=0

	if len(stuck) is 0:
		#print("break")
		break

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