Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

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

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

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

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

C++: #include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int time;
int n;
void visit(int);

int main(){
	time=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1;
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1;
		}
	}
	visit(0);
	// ??¨???????????????????????????????????°?¨????????????¨??????
	for(i=0;i<n;i++){
		cout<< i+1 << " "<<d[i]<< " "<<f[i];
		cout<<endl;
	}
	return 0;
}

void visit(int k){
	int i;
	d[k]=++time;
	for(i=0;i<n && f[k]==-1;i++){
		if(map[k][i]==1&&d[i]==-1){
			visit(i);
		}
	}
	f[k]=++time;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
int color[MAX], d[MAX], f[MAX], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0){
            continue;
        }
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0; u < n; u++) color[u] = WHITE;
    tt = 0;

    for(u = 0; u < n; u++){
        if(color[u] == WHITE) {
            dfs_visit(u);
        }
    }

    for(u = 0; u < n; u++){
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}


int main(){
    int i, j, u, k, v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> u >> k;
        for(j = 0; j < k; j++){
            cin >> v;
            M[u-1][v-1] = 1; 
        }
    }

    dfs();
    return 0;

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

vector<int> g[105];
int d[105], f[105], visited[105];
int t = 1;

void dfs(int x){
    d[x] = t++;
    visited[x] = 1;
    for(int y: g[x]){
        if(visited[y] == 1) continue;
        dfs(y);
    }
    f[x] = t++;
}

int main(){
    int n;
    cin >> n;
    rep(i,n+1){
        d[i] = 0;
        f[i] = 0;
        visited[i] = 0;
    }
    rep(i,n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for(int i = 1; i <= n; i++){
        if (visited[i] == 0){
            dfs(i);
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int n;
int d[101], v[101];
int graph[101][101] = {};

int solve(int k, int cnt)
{
	d[k] = cnt;
	int nowcnt = cnt;
	for(int i = 0; i < n; i++){
		if(d[i] < 0 && graph[k][i] > 0) nowcnt = solve(i, nowcnt + 1);
	}
	return v[k] = nowcnt + 1;
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		d[i] = -1;
		v[i] = -1;
		int u, k;
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			v--;
			graph[u][v] = 1;
		}
	}
	solve(0, 1);
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << d[i] << " " << v[i] << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <math.h>

using namespace std;

long long inf=1000000007;
vector<bool> seen(10000,false);

void dfs(long long &cnt,long long now,vector<long long> &d,vector<long long> &f,vector<vector<long long>> kankei){
	seen.at(now)=true;
	cnt++;
	d.at(now)=cnt;

	for(auto a:kankei.at(now)){
		if(seen.at(a)) continue;

		dfs(cnt,a,d,f,kankei);
	}

	cnt++;
	f.at(now)=cnt;

	return;
}

int main(){
	long long n;
	cin>>n;
	vector<vector<long long>> kankei(n+1);

	for(long long i=1;i<=n;i++){
		long long k,u;
		cin>>k>>u;
		vector<long long> vec(u);
		for(long long j=0;j<u;j++){
			cin>>vec.at(j);
		}
		sort(vec.begin(),vec.end());

		kankei.at(k)=vec;
	}

	vector<long long> d(n+1,0);
	vector<long long> f(n+1,0);
	long long cnt=0;

	for(long long i=1;i<=n;i++){
		if(seen.at(i)) continue;

		dfs(cnt,i,d,f,kankei);
	}

	for(long long i=1;i<=n;i++){
		cout<<i<<" "<<d.at(i)<<" "<<f.at(i)<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<list>
using namespace std;

#define MAX_N 101

int counter;
int d[MAX_N];
int f[MAX_N];

void DFS(list<int>* G, int n){
	counter++;
	d[n] = counter;
	list<int>::iterator it;
	for(it=G[n].begin(); it!=G[n].end(); it++){
		if(d[*it-1]==0) DFS(G, *it-1);
	}
	counter++;
	f[n] = counter;
}

int main()
{
	counter = 0;
	for(int i=0; i<MAX_N; i++) d[i]=f[i]=0;
	int n;cin>>n;
	list<int> G[n];
	
	// input Graph data
	for(int i=0; i<n; i++){
		int u, k, v;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			cin >> v;
			G[u-1].push_back(v);
		}
	}
	// DFS
	for(int i=0; i<n; i++){
		if(d[i]==0){
			DFS(G, i);
		}
	}
	// Output Result
	for(int i=0; i<n; i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}