Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include<iostream>
#include<vector>
#include<queue>

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time = 1) {
	cout << now << endl;
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) {
		if (!checked[adjacent[now][i]]) {
			time = dfs(adjacent[now][i], time + 1);
		}
	}
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(n);

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

	dfs(0, 1);
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
	}

}

C++: #include<iostream>
#include<stack>
#include<string.h>
using namespace std;
//void haichi(int);
int MA[101][101];
int n,cnt=1,Flag;
int id[101],d[101],f[101];
stack<int> S;
int main(void){
	int u,k,v;
	memset(MA,0,sizeof(MA));
	for(int i=1;i<=100;i++){
		id[i] = 0;
		d[i] = 0;
		f[i] = 0;
	}
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> u >> k;
		for(int j=0;j<k;j++){
			cin >> v;
			MA[u][v]=1;
		}
	}
	S.push(1);
	d[1] = 1;
	while(!S.empty()){
		Flag=0;
		/*if(d[S.top()] == 0)
			d[S.top()]=cnt;*/
		cnt++;
		for(int i=1;i<=n;i++){  //i=S.top();
			if(MA[S.top()][i]==1 && d[i] == 0){
				MA[S.top()][i]=0;
				S.push(i);
				//cout << "PUSH " << S.top() << endl;;
				d[S.top()]=cnt;
				Flag=1;
				break;
			}
		}
		if(Flag==0){
			//cout << "POP " << S.top() << endl;
			if(f[S.top()]==0) f[S.top()] = cnt;
			S.pop();
		}
	}
	for(int i=1;i<=n;i++){
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int map[101][101];
int all = 0;
int start[101];
int end_2[101];
int n;
void dps(int k) {
	start[k] = ++all;
	for (int i = 1; i <= n; i++) {
		if (map[k][i] && start[i] == 0) {
			dps(i);
		}
	}
	end_2[k] = ++all;
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		int m;
		cin >> m;
		for (int j = 0; j < m; j++) {
			int b;
			cin >> b;
			map[a][b] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (start[i] == 0) {
			dps(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << start[i] <<" "<< end_2[i]<<endl;
	}
}

C++: #if 0

#endif

#include <iostream>
#include <vector>
using namespace std;

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[cur][dst]==1&&c[dst]==0){
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	int G[110][110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			G[u][tmp]=1;
		}
	}
	
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
	}
}

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

vector<int> ans1; //訪れた時間を格納する
vector<int> ans2; //再び訪れた時間

int t = 0;

void dfs(Graph &G, int v = 0){ //vは現在の頂点
    t++;
    ans1.at(v) = t; //行くときに時間を記録する
    for(auto nv: G.at(v)){
        if(ans1.at(nv)) continue; //一回以上訪れたなら行かない
        dfs(G, nv);
    }
    t++;
    ans2.at(v) = t;
}

int main(){
    int n; cin >> n;
    Graph G(n); //以下0-indexed
    ans1.resize(n);
    ans2.resize(n);
    for(int i = 0; i < n; i++){ //グラフを隣接リストとして入力
        int a, b; cin >> a >> b;
        for(int j = 0; j < b; j++){
            int k; cin >> k; k--;
            G.at(i).push_back(k);
        }
    }
    for(int i = 0; i < n; i++){
        if(ans1.at(i) == 0) dfs(G, i);
    }
    for(int i = 0; i < n; i++){ //答えの出力
        cout << i+1 << " " << ans1.at(i) << " " << ans2.at(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;

constexpr int LEN = 105;
bool ga[LEN][LEN];
int d[LEN], f[LEN];

int dfs(int id, int time, const int n){
	int	t = ++time;
	if(d[id] < 0) d[id] = t;
	rep(i, n)
		if(ga[id][i] && (d[i] < 0)) t = dfs(i, t, n);
	if(f[id] < 0) f[id] = ++t;

	return t;
}

int main(){
	memset(d, -1, LEN*sizeof(int));
	memset(f, -1, LEN*sizeof(int));
	memset(ga, 0, LEN*LEN*sizeof(bool));
	int n; cin >> n;
	rep(i, n){
		int u, k; cin >> u >> k;
		rep(j, k){
			int v; cin >> v;
			ga[u-1][v-1] = 1;
		}
	}

	int t = 0;
	rep(id, n) if(d[id] < 0) t = dfs(id, t, n);
	rep(i, n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u[200],k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
int Gcounter;
int Fcounter;
int Find;
void dfs(int where){
  Find++;
  //cout << "where " << where << " " << Find << endl; 
 GetIt[where]=Find;
  //cout << "GetIt[" << where << "] = " << GetIt[where] << endl;

  if(k[where] != 0){ 
    for(int i=0;i<k[where];i++){
      if(!used[imap[where][i]]){
	Gcounter++;

	used[imap[where][i]] = true;
	dfs(imap[where][i]);

      }
    }
  }
  Find++;
    FinIt[where] = Find;
     
}
 
int main(){
  
  int ad;
   
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u[i];
    cin >> k[u[i]];
    for(int j=0;j<k[u[i]];j++){
      cin >> ad;
      imap[u[i]][j] = ad;
    }
  }
 
 
  for(int j=0;j<200;j++)used[j] = false;
  Gcounter=Fcounter=1;
 
  Find = 0;
  int Index=0;
  bool fin = true;
  fincou = 1;

  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	used[u[i]]=true;
	dfs(u[i]);

      }
    }
    
    //dfs(u[0]);   

   
  
  //cout << "counter - " << Find << ", F" << fincou << endl;
  for(int i=0;i<n;i++){
    cout << u[i] << " " << GetIt[u[i]]  << " " << FinIt[u[i]];
    cout << endl;
  }
 
  return 0;
}