Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

Python: 
def DFS(A = [0], i = 0, d = [0], f = [0], time = 1):
    for j in range(len(d)):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(A, j, d, f, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

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

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

Python: def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1

n=int(input())
adjlist=[list(map(int,input().split()))[2:] for _ in range(n)]
d=[-1]*n
f=[-1]*n
t=1
for i in range(1,n):
    if d[i-1]<0:
       dfs(adjlist,i)
for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i]))

Python: 
n=int(input())

l=[[0 for i in range(n)] for j in range(n)]##静的確保 隣接行列
d=[0 for i in range(n)]##発見
f=[0 for i in range(n)]##完了
stack=[]##スタック
check=[]

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1
##print("---隣接行列---")
##print(l)

time=1


while len(check)<n:
    for i in range(n):
        if i+1 not in check:
            stack+=[i+1]
            d[i]=time
            break
        else: pass

    while len(stack)!=0:
        ##print("----------while---------")
        for i in range(n):
            if l[stack[-1]-1][i]==1 and not i+1 in check and i+1 not in stack and stack[-1]-1!=i:
                time+=1
                d[i]=time
                stack+=[i+1]

               ## print("stack:",stack)
               ## print("check:",check)
               ## print("d[",i,"]:",d[i])
                break
            elif i==n-1:
##最深    
                check+=[stack[-1]]
                time+=1
                f[stack.pop()-1]=time

               ## print("f[",i,"]:",f[i])
               ## print("check:",check)
    time+=1


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

Python: n = int(input())
A = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 1

def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1 

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

Python: stack=[]
n=int(input())
color=[]
graph={}
d_time=[]
f_time=[]
time=0
root=[i for i in range(1,n+1)]

for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    color=["white" for l in range(n+1)]
    d_time=[0 for j in range(n+1)]
    f_time=[0 for j in range(n+1)]
    for k in range(tmp[1]):
        graph[tmp[0]][tmp[2+k]]=1
        if tmp[2+k] in root:
            root.remove(tmp[2+k])

def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time

if root==[]:
    function(1)
else:
    for i in range(len(root)):
        function(root[i])

for i in range(1,n+1):
    print(i,d_time[i],f_time[i])

Python: n = input()

color = [0 for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
X = [0 for i in range(n)]

def dfsv(u):
  color[u] = 1
  t += 1
  d[u] = t
  for v in range(n):
    if M[u][v] == 1 and color[v] == 0:
      dfsv(v)
  color[u] = 2
  t += 1
  f[u] = t

def dfs():
  t = 0
  for u in range(n):
    if color[u] == 0:
      dfsv(u)
  for u in range(n):
    print (u+1, d[u], f[u])

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

dfs()

Python: n = int(input())

adj = [0]*n # adjacent list

for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))

c = ['w']*n # color of each vertex
d = [0]*n # discovery time for each vertex
f = [0]*n  # finish time for each vertex
time = 0

def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
    
for u in range(n):
    if c[u] == 'w':
        DFS_visit(u)
        
        
for u in range(n):
    print(f"{u+1} {d[u]} {f[u]}")

Python: def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if f[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1].append(v - 1)
    adj[u - 1].sort()

d = [1 for _ in range(n)]
f = [-1 for _ in range(n)]
d, f, _ = dfs(adj, 0, d, f, 0)

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