Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include <stdio.h>
int size[101],g[101][101],x[101], y[101], k, d;
void dfs(int z){
  int i;
  x[z] = d++;
  for(i=1;i<=size[z];i++) if(!x[g[z][i]]) dfs(g[z][i]);
  y[z] = d++;
}
 
main(){
  int i, j, a;
  d=1;
  scanf("%d", &k);
  for(i=1;i<=k;i++){
    x[i] = y[i] = 0;
    scanf("%d", &a);
    scanf("%d", &size[a]);
    for(j=1;j<=size[a];j++) scanf("%d", &g[a][j]);
  }
  for(i=1;i<=k;i++){
    if(!x[i]) dfs(i);
  }
  for(i=1;i<=k;i++){
    printf("%d %d %d\n", i, x[i], y[i]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int MAX_N = 100;
const int INF = 1e9;

int n;
int d[MAX_N], f[MAX_N];
vector<int> g[MAX_N];

int t = 1;

void dfs(int v) {
    if (d[v] == INF) d[v] = t++;
    for (auto u : g[v]) {
        if (d[u] == INF) dfs(u);
    }
    if (f[v] == INF) f[v] = t++;
}

int main() {
    fill(d, d+MAX_N, INF);
    fill(f, f+MAX_N, INF);
    cin >> n;
    for (int i = 0, u, k; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0, v; j < k; j++) {
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    for (int i = 0; i < n; i++) dfs(i);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

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

void dfs_init();
void dfs(int u);

int n,*d,*f,time;
string *color; bool **M;

int main(){
	cin>>n;
	color = new string[n];
	M = new bool*[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	d = new int[n]; f = new int[n];

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) M[i][j] = false;
	}

	int deg,vertex,temp;
	for(int i=0;i<n;i++){
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>temp;
			M[vertex-1][temp-1] = true;
		}
	}

	dfs_init();

	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;

	delete [] color;
	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] f;
}

void dfs_init(){
	for(int i=0;i<n;i++)
		color[i] = "WHITE";
	dfs(0);
}

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=0;v<n;v++){
		if(M[u][v] && color[v]=="WHITE")
			dfs(v);
	}
	color[u] = "BLACK";
	f[u] = ++time;
}

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;
	}
}