Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

Python: import sys
input = lambda: sys.stdin.readline().rstrip() 
import bisect as bs

def resolve():
    n = int(input())
    ukv = [list(map(int, input().split())) for _ in range(n)]

    d = [-1]*n
    f = [-1]*n
    stk = []
    status = [0]*n

    t = 1
    for i in range(n):
        if status[i]==0:
            stk.append(i)
            while len(stk)>0:
                a = stk[-1]
                if status[a]==0:
                    d[a] = t
                    t += 1
                    status[a] = 1
                elif status[a]==1:
                    stk.pop()
                    f[a] = t
                    t += 1
                    status[a] = 2
                else:
                    stk.pop()
                for i in reversed(ukv[a][2:]):
                    if status[i-1]==0:
                        stk.append(i-1) 

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

if __name__ == '__main__':
    resolve()

Python: n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

v_color = ["WHITE"] * (n+1) # WHITE:????¨???????GRAY:?¨??????????BLACK:??¢?´¢??????
d = [0] * (n+1)
f = [0] * (n+1)
stack = []

def DFS(u):
    time = 0
    stack.append(u)
    
    while stack != []:
        u = stack[-1]
        time += 1
        
        v_color[u] = "GRAY"
        if d[u] == 0:
            d[u] = time
        
        for Next in graph[u-1][2:]:
            if v_color[Next] == "WHITE":
                stack.append(Next)
                break
        
        else:
            v_color[u] = "BLACK"
            f[u] = time +1
            stack.pop()
        
DFS(1)
    
for i in range(1,n+1):
    print(i,d[i],f[i])

Python: N = int(input())

Graph = {}
Node_list = []
visited = {}
d = {}
f = {}
t = 1

for i in range(N):
    
    tmp = input().split()
    id = tmp[0]
    Node_list.append(id)
    visited[id] = False

    if int(tmp[1]) != 0:
        Graph[id] = tmp[2:]
    else:
        Graph[id] = []
 


def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1

for node in Node_list:
    dfs(node)

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

Python: n = int(input())
link = {}

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

    u, k = a.pop(), a.pop()
    link[u] = []
    for j in range(k):
        link[u] += [a.pop()]

d, f = {}, {}
t = 0


def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t


for u in range(1, n + 1):
    if u not in d: dfs(u)

for i in range(1, n + 1):
    print(i, 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
d[0]=1
stack+=[1]
check+=[-1]

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

           ## print("stack:",stack)
           ## 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)
            


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

Python: 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 = " ")

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

Python: N = int(input())
DG={}  # それぞれのnodeが持つ隣接リストを、キーをnodeにして管理
node_ls=[]
is_visited={}  # 訪れたかどうかを、nodeをキーに辞書で管理


# 有向グラフをディクトで管理することにする
for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)      # 1~n の順番
    is_visited[node_id] = False  # 訪れた時にTrueにする
    adj_num = int(tmp[1])    # 次数（隣接リストの数）
    if adj_num != 0:
        DG[node_id] = tmp[2:]  # 隣接リストを入れる
    else:
        DG[node_id] = []


d = {} # 発見した時刻を、nodeをキーにして保存する
f = {} # 隣接リストを調べ終えた時刻を、nodeをキーにして保存する
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:  # 1~n の順番
    dfs(node)
    
for node in node_ls:
    print(node, d[node], f[node])