Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

Python: def dfs(v, cnt):
  D[v] = cnt
  cnt += 1
  for c in edge[v]:
    if D[c] == -1:
      cnt = dfs(c, cnt)
  F[v] = cnt
  cnt += 1
  return cnt

N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
  u, _, *v = map(lambda x:int(x)-1, input().split())
  edge[u] = sorted(v)
D, F = [-1] * N, [-1] * N
c = 1
for i in range(N):
  if D[i] == -1:
    c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
  print(i + 1, d, f)

Python: # =============================================================================
#　Depth First Search
# =============================================================================
import sys
sys.setrecursionlimit(10**8)

N=int(input())
Graph=[list(map(int,input().split()))[2:] for _ in range(N)]
Graph.insert(0,[])
seen=[False for _ in range(N+1)]
first_order=[0]*(N+1)
last_order=[0]*(N+1)
time=1

def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1

for v in range(1,N+1):
    if not seen[v]:
        dfs(Graph,v)
for i in range(1,N+1):
    print(i,first_order[i],last_order[i])

Python: def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t
n = int(input())
A = [0]*(n+1)
S = [0]*(n+1)
F = [0]*(n+1)
DP = [0]*(n+1)
for i in range(n):
    A[i+1] = [int(i) for i in input().split()]
t = 0
for i in range(1,n+1):
    if not DP[i]:
        t+=1
        dfs(i)
for i in range(1,n+1):
    tmp = "{} {} {}".format(i,S[i],F[i])
    print(tmp)

Python: import sys
sys.setrecursionlimit(10**7)
time = 0
def input():
    return sys.stdin.readline()
n = int(input())
G = [[]]
d = [0]*(n+1)
f = [0]*(n+1)
for _ in range(n):
    G.append(list(map(int,input().split()))[2:])
def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time

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

Python: n=int(input())
#V[u]=[k,[v],d,f]
V=[[0,[],0,0]]
for i in range(n):
    v=[int(i) for i in input().split(" ")]
    u=v.pop(0)
    k=v.pop(0)
    v.sort()
    V.append([k,v,0,0])


def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1

time=1

while time<=2*n:
 for i in range(1,n+1):
     if V[i][2]==0:
         cur=i
         log=[i]
         break
     print(cur)
 while len(log)>0:
    if V[cur][2]==0:
        V[cur][2]=time
        time+=1


    x=is_finished(cur)
    if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass
for i in range(1,n+1):
    print(i,V[i][2],V[i][3])

Python: import sys
sys.setrecursionlimit(3000)

n = int(input())
X = []
for _ in range(n):
    x = list(map(int, input().split()))
    if x[1] != 0:
        X.append(x[2:])
    else:
        X.append([])

df = [[0, 0] for _ in range(n)]
t = 0
def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t

for i in range(n):
    search(i)

for i, x in enumerate(df):
    print('{} {} {}'.format(i + 1, x[0], x[1]))

Python: import sys
input = sys.stdin.readline

from collections import deque

S = deque([])

def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1


def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t


n = int(input())
#color
c = [0] * n
d = [0] * n
f = [0] * n

M = [[0] * n for _ in range(n)]
t = 0

for i in range(n):
    A = list(map(int, input().split()))
    getNeighbor(A,i)

for num in range(n):
    if d[num] == 0:
        dfs(num)

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

Python: from sys import stdin

d_num = int(stdin.readline().strip())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, stdin.readline().split())
    for v in neighbors:
        graph[u].append(v)

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

dfs(1, 1)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave)

Python: N = int(input())
UK = [list(map(int,input().split())) for _ in range(N)]

class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag

V = [i+1 for i in range(N)]
E = []
for i in range(N):
    for j in range(len(UK[i])-2):
        E.append((i+1,UK[i][j+2]))

g = Graph(V,E)

ts = [[0 for _ in range(2)] for _ in range(N+1)]
time = 0

def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time

for i in range(N):
    if g.v_color[i] == False:
        dfs(i+1)

for i in range(N):
    print(i+1,ts[i][0],ts[i][1])