Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include<iostream>

int d[101]={0};
int f[101]={0};
int us[101]={0};
int V[101][101]={0};
int t=1;
int n;

void tansaku(int x)
{
  d[x]=t++;
  us[x]++;
  for(int i=0;i<n;i++){
    if(V[x][i]==1 and us[i]==0){
      tansaku(i);
    }
  }
  f[x]=t++;
}


int main()
{
  int n;
  int u,k,v;
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>u>>k;
    for(int j=0;j<k;j++){
      std::cin>>v;
      V[u-1][v-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(us[i]==0){
      tansaku(i);
    }
  }
  for(int i=0;i<n;i++){
    std::cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100, MAX_K = 100;

int n, u, k, v[MAX_K];

vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
int t = 0;

void dfs(int);

int main() {
    // input
    cin >> n;
    REP(i, n) {
        cin >> u >> k;
        u--;
        REP(j, k) {
            cin >> v[j];
            v[j]--;
            G[u].PB(v[j]);
        }
    }

    // init d
    REP(i, n) d[i] = -1;

    // dfs
    REP(i, n) {
        if (d[i] == -1) dfs(i);
    }

    // output
    REP(i, n) {
        int id = i + 1;
        printf("%d %d %d\n", id, d[i], f[i]);
    }

    return 0;
}

void dfs(int pos) {
    d[pos] = ++t;
    REP(i, G[pos].size()) {
        int to = G[pos][i];
        if (d[to] != -1) continue;
        dfs(to);
    }
    f[pos] = ++t;
    return;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int N=101;

int n,tt=0;
vii M(N,vi(N,0));
vi color(N,WHITE),d(N),f(N),nt(N,0);

void dfs();
void dfs_visit(int);
int next(int);

int main(){
	int i,j,u,k,v;
	cin>>n;
	loop(i,0,n){
		cin>>u>>k;
		loop(j,0,k){
			cin>>v;
			M[u][v]=1;
		}
	}
	dfs();
}

void dfs(){
	int i;
	loop(i,1,n+1){
		if(color[i]==WHITE){
			dfs_visit(i);
		}
	}
	loop(i,1,n+1){
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
}

void dfs_visit(int r){
	stack<int> s;
	s.push(r);
	color[r]=GRAY;
	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;
		}
	}
}

int next(int u){
	int v;
	loop(v,nt[u]+1,n+1){
		nt[u]=v;
		if(M[u][v]){
			return v;
		}
	}
	return -1;
}

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

using namespace std;
int timetime = 0;

void dfs(int cur, vector<vector <int> > &list, vector<int> &d, vector<int> &f) {
		d[cur] =timetime;
		timetime +=1;
    for(int i = 0; i < list.size();i++){
      vector<int>::iterator it = list[cur].end();
	  vector<int>::iterator hoge = find(list[cur].begin(),list[cur].end(),i);
      if(d[i] == 0 && (hoge != it ) ){
        dfs(i,list,d,f);
      }
    }
    f[cur] = timetime;
    timetime +=1;
}

int main() {
  int np;
  int k,t,x;
  cin >> np ;
 
  vector <vector <int> > list(np);
  for(int i = 0;i<np;i++) {
    cin >> k;
    cin >> t;
    for(int j = 0; j < t ;j++) {
      cin >>x;
      list[k-1].push_back(x-1);
    }
  }
  vector <int> d(np,0);
  vector <int> f(np,0);
  dfs(0,list,d,f);
  for(int i = 0;i < np; i++){
    cout << i+1 <<" "<<d[i]+1 <<" "<<f[i]+1<<endl;
  }


  return 0;
}

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

struct time_check {
    int find_time, end_time;
};

int main() {
    int G[101][101] = {0};
    time_check t[101];

    for (int i = 1; i <= 100; i++) t[i].end_time = 0;

    stack<int> S;
    int n, u, v, k, elapsed=1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }
    S.push(1);
    t[1].find_time = 1;
    while (! S.empty()) {
        elapsed++;
        u = S.top();
        for (int i = 1; i <= n + 1; i++) {
            if (G[u][i] == 1 && t[i].end_time == 0) {
                t[i].find_time = elapsed;
                G[u][i] = 0;
                S.push(i);
                break;
            }
            if (i == n + 1) {
                t[u].end_time = elapsed;
                S.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << t[i].find_time << " " << t[i].end_time << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

void dfs_visit(int u){
    
    color[u] = GRAY;
    d[u] = ++tt;
    for(int v = 0; v < n; v++){
        if(M[u][v] == 0) continue;
        else if(color[v]== WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;

    f[u] = ++tt;
}



int main(){
    int u;
    int v;
    int k;



    scanf("%d",&n);

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


    for(int i=0; i<n; i++){
        scanf("%d",&u);
        scanf("%d",&k);
        for(int j=0; j<k; j++){
            scanf("%d",&v);

            M[u-1][--v] = 1;
        }
        
    }

    tt = 0;

    for(int i=0; i<n;i++) {
        if(color[i] == WHITE) dfs_visit(i);
    }

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

    return 0;

}

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

int G[110][110];
bool seen[110];
int d[110];
int f[110];
int N;
int t = 1;

void dfs( int s ){
    seen[s] = 1;
    d[s] = t++;
    for( int i = 0; i < N; i++ ){
        if( G[s][i] && !seen[i] ){
            dfs( i );
        }
    }
    f[s] = t++;
}

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

    for( int i = 0; i < N; i++ ){
        if( !seen[i] ){
            dfs( i );
        }
    }

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