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 <iostream>
#include <unordered_map>
#include <vector>


using namespace std;

int timecount = 0;

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap);

int main(){
  int u, i, id, k, j;
  cin >> u;
  unordered_map<int, vector<int> > mymap;

  for (i = 0; i < u; ++i){
    cin >> id >> k;
    vector<int> points;
    for (j = 0; j < k; ++j){
      int a;
      cin >> a;
      points.push_back(a);
    }
    mymap[id] = points;
  }
  
  bool visited[u+1];
  for (j = 1; j <= u; ++j){
    visited[j] = false;
  }
  visited[1] = true;

  int timearray[u+1];
  for (j = 1; j <= u; ++j){
    timearray[j] = 0;
  }
  int timearray_end[u+1];
  for (j = 1; j <= u; ++j){
    timearray_end[j] = 0;
  }

  dfs(1, u, visited, timearray, timearray_end, mymap);

  for (j = 1; j <= u; ++j){
    cout << j << " " << timearray[j] << " " << timearray_end[j]<< endl;
  }

}

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap){
  timecount++;
  timearray[cur] = timecount;

  for(int i = 1; i <= u; ++i){
    
    if((i!=cur)&&(find(mymap[cur].begin(), mymap[cur].end(), i) != mymap[cur].end())&&(!visited[i])){
      visited[i] = true;
      dfs(i, u, visited, timearray, timearray_end, mymap);
    }
  }
  timecount++;

  timearray_end[cur] = timecount;
}

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++;
	for(int i=1;i<=n;i++){
		if(a[local][i]){
			if(st[i]==0){
				dfs(i);
			}
		}
	}
	ed[local]=now++;
}
int main(){
	ios::sync_with_stdio(false);
	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;
		}
		for(int i=1;i<=n;i++){
			if(!st[i])
				dfs(i);
		}
		for(int i=1;i<=n;i++){
			cout<<i<<" "<<st[i]<<" "<<ed[i]<<endl;
		}
	}
	return 0;
}


//

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

void DFS(const Graph &G,int v,vector<bool> &seen,vector<int> &first_order,vector<int> &last_order,int &ptr){//深さ優先探索。
//引数は順にグラフ、始点(注目点)、探索済みかどうか、行きがけでの順番配列、帰りがけでの順番配列、順番カウンタ
//タイムスタンプ型のため、firstとlastでカウンタを共有
  first_order[v]=ptr++;//行きがけのカウント

  seen[v]=true;

  for(auto next_v : G[v]){
    if(seen[next_v]) continue;
    DFS(G,next_v,seen,first_order,last_order,ptr);
  }
  
  last_order[v]=ptr++;//帰りがけのカウント

  return ;

}

 
int main() {

  int n;  cin >> n ;

  Graph G(n+1);//頂点はn個。今回は数値にそのまま対応させるために+1した

  rep(i,n){
    int u,k;
    cin >> u >> k;
    if(k==0) continue;

    rep(j,k){
    int v;
    cin >> v;
    G[u].push_back(v);
    }
  }//入力終了

  vector<bool> seen(n+1,false);
  vector<int> first_order(n+1),last_order(n+1);
  int ptr=1;//今回はカウント1スタート
  for(int i=1;i<=n;i++){
  if(seen[i]) continue;
  DFS(G,i,seen,first_order,last_order,ptr);
  }

  for(int i=1;i<=n;i++){
    cout << i <<' '<< first_order[i] << ' ' << last_order[i] << endl;
  }

  return 0;
}

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

int n, G[101][101], S[101], T[101];

int dfs(int p, int s) {
    if (S[p] != 0) return 0;
    S[p] = s;
    s++;
    for (int i = 0; i < n; i++) {
        if (G[p][i] == 1) {
            s = max(s, dfs(i, s) + 1);
        }
    }
    T[p] = s;
    return s;
}


int main(void) {
    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(0, 1);

    for (int i = 0; i < n; i++)
        printf("%d %d %d\n", i + 1, S[i], T[i]);

    return 0;
}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

vector<bool> seen;
vl d, f;

void dfs(ll now, ll &time, vll &G){
    seen[now] = true;
    d[now] = time++;
    for(ll next : G[now]){
        if(seen[next]) continue;
        dfs(next, time, G);
    }
    f[now] = time++;
}

int main() {
    ll N;
    cin >> N;
    vll G(N);
    rep(i, N){
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k){
            ll t;
            cin >> t;
            t--;
            G[u].push_back(t);
        }
    }
    seen.assign(N, false);
    d.resize(N);
    f.resize(N);
    ll time = 1;
    rep(i, N){
        if(!seen[i]){
            dfs(i, time, G);
        }
    }
    rep(i, N){
        ll idx = i+1;
        cout << idx << " " << d[i] << " " << f[i] << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int G[101][101];
bool Memo[101];
int d[101];
int f[101];
int count1;

void dfs(int i, int n) {
  if (Memo[i]) {
    count1++;
    d[i] = count1;
    Memo[i] = false;
    for (int j = 0; j < n; j++) {
      if (G[i][j] == 1) {
        dfs(j,n);
      }
    }
    count1++;
    f[i] = count1;
  }
}

int main() {
  int n;
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      G[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int row,col;
    scanf("%d %d",&row,&col);
    for (int j = 0; j < col; j++) {
      int d;
      scanf("%d",&d);
      G[row - 1][d - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) Memo[i] = true;
  count1 = 0;
  dfs(0,n);
  for (int i = 0; i < n; i++) printf("%d %d %d\n",i+1,d[i],f[i]);
  return 0;
}