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++: #include <bits/stdc++.h>
using namespace std;
int d[110];
int f[110];
bool seen[110]={false};
void dfs(vector<vector<int> > &G,int &t,int v){
    seen[v] = true;
    d[v] = t;
    t++;
    for(int i=0;i<G[v].size();i++){
	int nv = G[v][i];
	if(!seen[nv]){ 
	    dfs(G,t,nv);
	}
    }
    f[v] = t;
    t++;
}
int main(void){
    int n; cin >> n;
    vector<vector<int> > G(n+1);
    for(int i=0;i<n;i++){
	int a,b;cin >> a >> b;
	for(int j=0;j<b;j++){
	    int c; cin >> c;
	    G[a].push_back(c);
	}
    }
    int t = 1;
    for(int i=1;i<=n;i++){
	if(seen[i]) continue;
	dfs(G,t,i);
    }
    for(int i=1;i<=n;i++){
	cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	cin>>n;
	vector<vector<int> > A(n);//????????????????????????-1?????\???????????????
	//??\???
	REP(i,n){
		int u,k;
		cin>>u>>k;
		A[i]=vector<int>(k,0);
		REP(j,k){
			int l;
			cin>>l;
			A[i][j] = l-1;
		}
	}
	//??¢?´¢
	stack<int> s;//??????????????????????????\???
	vector<int> dis(n,0);//??????????????????????????????
	vector<int> fin(n,0);//???????????????????????????
	s.push(0);//?????????0???????????????
	int time=0;
	while(!s.empty()){
	//REP(ss,3){
		int k = s.top();//??????????????????????????????
		if(dis[k]==0){
			time++;
			dis[k]=time;
			//cout<<"dis "<<k<<" / time "<<time<<endl;
		}
		bool isfinish=true;
		for(int i: A[k]){
			//cout<<"?????????"<<i<<endl;
			if(fin[i]==0){
				s.push(i);
				isfinish=false;
				break;
			}
		}
		if(isfinish){
			time++;
			fin[k]=time;
			s.pop();
			//cout<<"fin "<<k<<" / time "<<time<<endl;
		}
	}
	REP(i,n){
		cout<<i+1<<" "<<dis[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
#include <cassert>
#include <cmath>
using namespace std; typedef long long ll; ll an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P;
vector<int> v[100];
int ts, st[100], ed[100];

void dfs(int from) {
  if (st[from] == -1) st[from]=++ts;
  else return;
  for(int to:v[from]) {
    if (st[to] == -1) dfs(to);
  }
  if (ed[from] == -1) ed[from]=++ts; return;
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;i++) {
    int _, k; cin>>_>>k;
    for(int j=0;j<k;j++) {
      int x; cin>>x; x--;
      v[i].push_back(x);
    }
  }
  ts=0;
  fill(st, st+n, -1); fill(ed, ed+n, -1);
  for(int i=0;i<n;i++) dfs(i);
  for(int i=0;i<n;i++) {
    cout<<i+1<<" "<<st[i]<<" "<<ed[i]<<endl;
  } return 0;
}

C++: #include <iostream>

using namespace std;

int a[124][124] = {{}};
int start[124] = {};
int e[124] = {};
int c = 0;
int n;
void dfs(int k){
  if(start[k] != 0) return;
  c++;
  start[k] = c;

  for(int i = 0;i < n;i++){
    if(a[k][i] == 1){
      dfs(i);
    }
  }
  c++;
  e[k] = c;
}
int main(){

  int u,k,x;
  cin >> n;



  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> x;
      a[u - 1][x - 1] = 1;
    }
  }


  for(int i = 0;i < n;i++)  dfs(i);

  for(int i = 0;i < n;i++){
    cout << i + 1 << " " << start[i] << " " << e[i] << endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

vector<bool> seen;
vector<int> first;
vector<int> last;

void dfs(const vector<vector<int>> &g, int v, int &ptr){
  first[v] = ptr++;
  seen[v] = true;
  
  for(int i : g[v]){
    if(seen[i]) continue;
    dfs(g,i,ptr);
  }
  
  last[v] = ptr++;
}

int main() {
  int n;
  cin >> n;
  seen.assign(n,false);
  first.resize(n);
  last.resize(n);
  
  vector<vector<int>> g(n);
  
  rep(i,n){
    int u, k;
    cin >> u >> k;
    u--;
    vector<int> v(k);
    rep(j,k){
      cin >> v[j];
      v[j]--;
      g[u].push_back(v[j]);
    } 
  }
  int ptr = 1;
  rep(i,n){
    if(first[i] == 0){
      dfs(g,i,ptr);
    }
  }


  rep(i,n){
    cout << i + 1 << ' ' <<first[i] << ' ' << last[i] << endl;
  } 
}

C++: #include <iostream>
using namespace std;
int a[100][100]={},f[100]={},d[100]={},T[200]={};
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>a[u][j];
		}
	}
	T[1]=1;
	f[1]=1;
	for(int time=2;time<=2*n;time++){
		for(int j=0;j<100;j++){
			if(a[T[time-1]][j]==0){
				d[T[time-1]]=time;
				T[time]=T[f[T[time-1]]-1];
				break;
			}
			else if(f[a[T[time-1]][j]]==0){
				f[a[T[time-1]][j]]=time;
				T[time]=a[T[time-1]][j];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<f[i]<<" "<<d[i]<<endl;
	}
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = search(array, A, 1, n, 0);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}