Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

// u?????£??\??????v?????????????????????
int next(int u){
    for (int v = nt[u]; v < n ; v++) {
        nt[u] = v +1;
        if(M[u][v]) return v;
    }
    return -1;
}

//with stack

void dfs_visit (int r){
    for (int i = 0; i < n ; ++i) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    tt ++; d[r] = tt;

    while(! S.empty()){
        int u = S.top();
        int v = next(u);
        if( v != -1){
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++ tt;
        }
    }
}

void dfs(){
    int u;
    for (u = 0; u < n; ++u) {
        color[u] = WHITE;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == WHITE) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int u,v,k;
    
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < n ; ++j) {
         M[i][j] = 0;   
        }
    }
    
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        u --;
        for (int j = 0; j < k ; ++j) {
            cin >> v;
            v --;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #include <iostream>
using namespace std;
int n,g[100][100],c[100],f[100],e[100],t=1;
void dfs(int now){
  c[now]=1;
  f[now]=t;
  t++;
  for(int i=0;i<n;i++) if(g[now][i]&&c[i]!=1){
      dfs(i);
      t++;
    }
  e[now]=t;
}
int main(){

  int a,b,tmp;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=0;j<b;j++){
      cin>>tmp;
      g[a-1][tmp-1]=1;
    }
  }
  for(int i=0;i<n;i++) if(c[i]!=1){
      dfs(i);
      t++;
    }

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

  return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
ll mod=2e12;
ll cnt=0;
#define max 100005
#define nil -1
int white=0;
int gray=1;
int black=2;
int n,t=0;
int color[101],d[101],f[101],m[101][101];

void DFS(int i){
  color[i]=gray;
  d[i]=++t;
  for(int j=0;j<=n;j++){
    if(m[i][j]==1&&color[j]==white)DFS(j);
  }
  color[i]=black;
  f[i]=++t;
}

int main(){
  int q,w,e;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>q>>w;
    for(int j=1;j<=n;j++)m[i][j]=0;
    for(int j=1;j<=w;j++){
      cin>>e;
      m[i][e]=1;
    }
  }

  rep(i,100)color[i]=white;

  for(int i=1;i<=n;i++){
    if(color[i]==white)DFS(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;
int n;
int u[101], k[101];
int d[101], f[101];
vector<vector<int>> g;
bool visit[101];
int t = 0;
void dfs(int a){
	if(visit[a]==false){
	 	visit[a] = true;
	 	t++;
	 	d[a] = t;
		for(auto c : g[a]){
			dfs(c);
		}
		t++;
		f[a] = t;
	}else{
		return;
	}
	return;
}

int main() {
	cin >> n;
	g.resize(n+1);
	for(int i=1;i<=n;i++){
		d[i] = 0;
		f[i] = 0;
		visit[i] = false;
		cin >> u[i] >> k[i];
		if(k[i]){
			for(int j=1;j<=k[i];j++){
				int v; cin >> v;
				g[u[i]].push_back(v);
			}
		}
	} 
	for(int i=1;i<=n;i++){
		if(visit[i]==false) dfs(i);
	}
	for(int i=1;i<=n;i++){
		cout << i << ' ' << d[i] << ' ' << f[i] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 110;
vector<int> G[MAX];
int dtime[MAX];
int ftime[MAX];
int n;
int tim;

void dfs(int p) {
    dtime[p] = ++tim;
    for (int i = 0; i < G[p].size(); i++) {
        dfs(G[p][i]);
    }
    ftime[p] = ++tim;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) G[i].clear();
    tim = 0;
    for (int i = 1; i <= n; i++) {
        int p, k;
        scanf("%d %d", &p, &k);
        while (k--) {
            int ne = 0;
            scanf("%d", &ne);
            G[p].push_back(ne);
        }
    }
    dfs(1);
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, dtime[i], ftime[i]);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n; vector<vector<int> >vec(n, vector<int>());
	rep(i, 0, n) {
		int u, k; cin >> u >> k;
		u--;
		rep(j, 0, k) {
			int v; cin >> v; v--;
			vec[u].push_back(v);
		}
	}
	const int DONE = 1;
	const int YET = 0;
	vector<int>check(n, 0);
	vector<pair<int, int> >stamp(n);
	stack<int>S;
	S.push(0);
	int t = 1;

	while (!S.empty()) {
		int u = S.top();
		if (check[u] == YET) {
			stamp[u].first = t++;
			check[u] = DONE;
		}
	here:
		if (DBG) {
			cout << "t == " << t << endl;
			rep(x, 0, n) {
				cout << x+1<<" "<<stamp[x].first << " " << stamp[x].second << endl;
			}
		}
		rep(i, 0, vec[u].size()) {
			if (check[vec[u][i]] == YET) {
				S.push(vec[u][i]);
				check[vec[u][i]] = DONE;
				stamp[vec[u][i]].first = t++;
				u = vec[u][i];
				goto here;
			}
		}
		u = S.top(); S.pop();
		stamp[u].second = t++;
	}
	
	rep(i, 0, n) {
		cout << i + 1 << " " << stamp[i].first << " " << stamp[i].second << endl;;
	}

	return 0;
}

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <int> m[103];
int kakunin[103]={0};
int d[103];
int f[103];
int cnt=1;
void dfs(int num){
    d[num]=cnt++;
    for(int i=0;i<m[num].size();i++){
        if(kakunin[m[num][i]]==0){kakunin[m[num][i]]=1;dfs(m[num][i]);}}
    f[num]=cnt++;
}
int main() {
    int n,a,tmp,id;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id;
        cin>>a;
        for(int j=0;j<a;j++){
            scanf("%d",&tmp);
            m[id].push_back(tmp);
        }
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i];}
}