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: from collections import deque
n = int(input())
data = [None]*n
unvisited = [1]*n
for _ in range(n):
    a,*b = map(int,input().split())
    a -= 1
    data[a] = deque([i-1 for i in b[1:]])

d = [-1]*n
f = [-1]*n
t = 0

dq = deque([])
for u in range(n):
    if unvisited[u]:
        dq.append(u)
        unvisited[u] = 0
        t += 1
        d[u] = t
        while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t

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

Python: def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t


if __name__ == "__main__":
    N = int(input())
    es = [[] for _ in range(N+1)]
    for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
    D = [0 for _ in range(N+1)]
    F = [0 for _ in range(N+1)]
    t = 0
    for i in range(1, N+1):
        if D[i] == 0:
            dfs(i)
    for i in range(1, N+1):
        print(i, D[i], F[i])

Python: 
n = int(input())
M = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    temp = list(map(int, input().split()))
    for i in range(temp[1]):
        M[temp[0]-1][temp[i+2]-1] = 1

WHITE = 0
GRAY = 1
BLACK = 2
color, d, f = [WHITE for i in range(n)]
t = 1

def visit(u):
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u-1][v-1] == 0):
            continue
        if (color[v] == WHITE):
            visit(v)
    color[u] = BLACK
    f[u] = t
    t += 1

for u in range(n):
    if (color[u] == WHITE):
        visit(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ")

Python: def visit(u):
    global color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
                visit(v)
    color[u] = BLACK
    f[u] = t
    t += 1

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

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d, f = [0 for i in range(n)]
t = 1

for u in range(n):
    if (color[u] == WHITE):
        visit(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ")

Python: import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
    input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
detect_time = [1] * n
finish_time = [0] * n
is_visit = [False] * n
stack = [1]
time = 1

while(len(stack) != 0):
    time += 1
    now = stack[-1] - 1
    if len(input_line[now]) == 0:
        finish_time[stack.pop()-1] = time
    else:
        detect = input_line[now].pop(0)
        if is_visit[detect-1]:
            finish_time[stack.pop()-1] = time
            continue
        stack.append(detect)
        detect_time[detect-1] = time
        is_visit[detect-1] = True

for id in range(n):
    print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id]))

Python: from collections import deque
n = int(input())
graph = [deque([]) for _ in range(n+1)]
ans = [[i, ] for i in range(n+1)]
for i in range(n):
  u, k, *v = list(map(int, input().split()))
  for j in v:
    graph[u].append(j)
stack = deque()
stack.append(1)
marked = []
t = 0
def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t)
for i in range(1, n+1):
  if len(ans[i])==1:
    dfs(i)
for i, x in enumerate(ans):
  if i==0:
    continue
  print(*x)

Python: from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()

def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb()

n = int(input())
g = [None] * (n+1)
start = [None] * (n+1)
end = [None] * (n+1)
lb = iter(range(1,2*n+1)).__next__
for _ in range(n):
    u,k,*vk = map(int,input().split())
    g[u] = vk
for v in range(1,n+1):
    if start[v] != None:
        continue
    dfs(v)

for i in range(1,n+1):
    print(i,start[i],end[i])

Python: n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    u, k, *v = map(int, input().split())
    u -= 1
    G[u].extend(v)
seen = [False] * n
d = [-1] * n
f = [-1] * n
t = 1

def dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t

def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G)

if __name__ == "__main__":
    main()