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

C++: #include<iostream>
using namespace std;
#define MAX 100

int mat[MAX][MAX] = {};
int n;
int time = 0;
int d[MAX] = {}, f[MAX] = {};
bool c[MAX];

void dfs_visit(int u){
    c[u] = true;
    d[u] = ++time;
    for(int i = 0; i < n; i++){
        if(mat[u][i] == 0)  continue;
        if(!c[i])   dfs_visit(i);
    }
    f[u] = ++time;
}

void dfs(){
    for(int i = 0; i < n; i++){
        if(!c[i])   dfs_visit(i);
    }

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

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int x, k, y;
        cin >> x >> k;
        while(k-- > 0){
            cin >> y;
            mat[x-1][y-1] = 1;
        }
    }

    dfs();
    return 0;
}

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

const int MAX_N = 100;
int to[MAX_N][MAX_N];
int ans[MAX_N][2];
int depth = 1;

void dfs(int x) {
  if (ans[x][0] == -1) ans[x][0] = depth++;
  for (int i=0; to[x][i] != -1; i++) {
    dfs(to[x][i]);
  }
  if (ans[x][1] == -1) ans[x][1] = depth++;
}

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      to[i][j] = -1;
    }
    ans[i][0] = ans[i][1] = -1;
  }
  for (int i=0; i<N; i++) {
    int tmp, n;
    cin >> tmp >> n;
    for (int j=0; j<n; j++) {
      int t;
      cin >> t; t--;
      to[i][j] = t;
    }
  }

  dfs(0);
  for (int i=0; i<N; i++) {
    cout << i+1 << " " << ans[i][0] << " " << ans[i][1] << endl;
  }
  return 0;
}