Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  time[102][2];
int ct = 1;
inline void search(int t) {
	if(!time[t][0]) time[t][0] = ct++;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		time[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {
	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	search(1);
	for (int i = 1; i <= n; i++) {
		cout << i << " " << time[i][0] << " " << time[i][1] << endl;
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 0;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    for(int i = 1;i <= n;i++){
        if(d[i]==-1){
            tm++;dfs(i);}
        
    }
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

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

const int Max = 105;
int G[Max][Max], color[Max], d[Max], f[Max];
int t, n;

void dfs_visit(int u)
{
    color[u] = 0;
    d[u] = ++t;
    for(int j=0; j<n; j++)
    {
        if(!G[u][j]) continue;
        if(color[j]==-1)
            dfs_visit(j);
    }
    color[u] = 1;
    f[u] = ++t;
}
void dfs()
{
    memset(color, -1, sizeof(color));
    t = 0;
    for(int i=0; i<n; i++)
    {
        if(color[i]==-1)
            dfs_visit(i);
    }
    for(int i=0; i<n; i++)
    {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}
int main()
{
    int u, k, v;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> u >> k;
        for(int j=0; j<k; j++)
        {
            cin >> v;
            G[u-1][v-1] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #include<bits/stdc++.h>
//cout<<setprecision(1)<<fixed<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;
#define eps 1e-7
//#define Kongxiangzhouye
int n;
int a[123][123];
int st[123];
int ed[123];
int now;
void dfs(int local){
	st[local]=now++;
	int flag=1;
	for(int i=1;i<=n;i++){
		if(a[local][i]==1){
			if(st[i]==0){
				flag=0;
				dfs(i);
			}
		}
	}
	ed[local]=now++;
}
int main(){
	ios::sync_with_stdio(false);
	#ifdef Kongxiangzhouye
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	while(cin>>n){
		memset(a,0,sizeof(a));
		memset(st,0,sizeof(st));
		memset(ed,0,sizeof(ed));
		for(int i=0;i<n;i++){
			int t,m;
			cin>>t>>m;
			for(int i=0;i<m;i++){
				int te;
				cin>>te;
				a[t][te]=1;
			}
			now=1;
		}
		dfs(1);
		for(int i=1;i<=n;i++){
			cout<<i<<" "<<st[i]<<" "<<ed[i]<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int n;
int cnt1 = 0; 
vector<int> d(n);
vector<int> f(n);
void dfs(const Graph &G, int v){
    cnt1++;
    d[v - 1] = cnt1;
    for(auto nv : G[v - 1]){
        if(d[nv - 1] != 0) continue;
        dfs(G, nv);
    }
    cnt1++;
    f[v - 1] = cnt1;
}

int main(){
    cin >> n;
    Graph G(n); 
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(b == 0) continue;
        for(int j = 0; j < b; j++){
            int x; cin >> x;
            G[a - 1].push_back(x);
        }
    }
    d.assign(n, 0);
    f.assign(n, 0);
    for(int i = 1; i <= n; i++){
      if(d[i - 1] == 0) dfs(G, i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i - 1] << " " << f[i - 1] << endl; 
    }
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

using Graph = vector<vector<ll>>;
Graph G;
ll d[110], f[110];

void DFS(ll v, ll &t)
{
	if (d[v] != -1) return;
	d[v] = t;

	++t;
	for (auto &nv : G[v])
	{
		DFS(nv, t);
	}
	f[v] = t;
	++t;
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	G.resize(N);
	for (ll i = 0; i < N; ++i)
	{
		ll n, k; cin >> n >> k;
		--n;
		for (ll j = 0; j < k; ++j)
		{
			ll v; cin >> v;
			--v;
			G[n].push_back(v);
		}
		sort(G[n].begin(), G[n].end());
	}
	fill(d, d+110, -1);
	fill(f, f+110, -1);

	ll t = 1;
	for (ll v = 0; v < N; ++v)
	{
		if (d[v] == -1)
			DFS(v, t);
	}

	for (ll i = 0; i < N; ++i)
	{
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
}