Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include<iostream>
#include<cstdio>
#define N 100
#define  GRAY 1
#define BLACK 2
using namespace std;
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0;v<n;v++)
  {  
    if(M[u][v] == 0)
     continue;
  if(color[v] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) dfs_visit(u);
  }
  for(u = 0;u<n;u++)
  {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for( i = 0;i<n;i++)
  {  for( j = 0;j<n;j++)
        M[i][j] = 0; }
  for( i =0;i<n;i++)
   {
     scanf("%d %d",&n,&k);
     u--;
     for( j = 0;j<k;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}

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

int n,t;
int d[100],f[100];
bool graph[100][100], visited[100];

void dfs(int v){
    visited[v]=true;
    t++;
    d[v]=t;

    for(int v2=0; v2<n; v2++){
        if(graph[v][v2] && visited[v2]==false) dfs(v2);
    }

    t++;
    f[v]=t;
}

int main(void){
    cin >> n;
    t=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            graph[i][j]=false;
        }
    }
    for(int i=0; i<n; i++){
        int v,k; cin >> v >> k;
        for(int j=0; j<k; j++){
            int w; cin >> w;
            graph[v-1][w-1]=true;
        }
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
int a[101][101],num[101],tt[101][2];
bool vis[101];
int n,u,k,x,t=1;
void dfs(int k){
     tt[k][0]=t; t++;
     vis[k]=true;
	 for (int i=1; i<=num[k]; i++){
	     if (!vis[a[k][i]]){
	     	dfs(a[k][i]);
		 }
     }
	 tt[k][1]=t; t++;
}
int main(){
	memset(a,0,sizeof(a));
	memset(vis,false,sizeof(vis));
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>u>>k;
		num[u]=k;
		int j=0;
		while (k--){
			  cin>>x;
			  a[u][++j]=x;
		}
	}
	for (int i=1; i<=n; i++)
	    if (!vis[i])
		   dfs(i); 
	for (int i=1; i<=n; i++){
		cout<<i;
		for (int j=0; j<2; j++)
		    cout<<' '<<tt[i][j];
		cout<<'\n';
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

	int time = 0;
	int d[101];
	int f[101];
	int num;
	int graph[101][101] = {0};

void dfs(int x){
	time++;
	d[x] = time;

	for(int i=1;i<=num;i++){
		if(graph[x][i] == 1 && d[i]==0){
			printf("%d -> %d\n",x,i);
			dfs(i);
		}
	}
	f[x] = ++time;
}

int main(){
	int hon;
	int eda;
	int ver;

	cin>>num;
	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}

	dfs(1);

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

	return 0;
}

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

using namespace std;

vector<int> d(101, -1), f(101, -1);
vector<vector<int> > c;

int n, u, k, v;
int dfs(int node, int time) {
    d[node] = time;
    for(int i=0; i<n; ++i) {
        if(c[node][i]==1&&d[i]==-1) time = dfs(i, time+1);
    }
    time++;
    f[node] = time;
    return time;
}

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

    bool isFinished = false;
    int node = 0;
    int time = 0;
    while(isFinished==false) {
        time++;
        time = dfs(node, time);
        isFinished = true;
        for(node=0; node<n; node++) {
            if(d[node]==-1) {
                isFinished=false;
                break;
            }
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
using Graph=vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin>>N;
    Graph G(N);
    for(int i=0;i<N;i++){
        int u,k; cin>>u>>k;
        u--;
        while(k--){
            int v; cin>>v;
            v--;
            G[u].push_back(v);
        }
    }
    vector<int> d(N,-1),f(N);
    int time=1;
    function<void(int)> dfs=[&](int v)
    {
        d[v]=time++;
        for(int u:G[v]) if(d[u]==-1){
            dfs(u);
        }
        f[v]=time++;
    };

    for(int i=0;i<N;i++) if(d[i]==-1){
        dfs(i);
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}

C++: #include <stdio.h>

int A[101][101];
int ans[101][3];
int an = 1;


int judge(int i, int j){
  if(ans[i][j] == 0){
    ans[i][j] = an;
    an++;
  }
}

int serch(int a[101][101], int  ni, int n){
  int  j;
  
  for(j=0; j<n; j++){
    if(A[ni][j] == 1){
      judge(j, 1);
      serch(A, j, n);
    }
  }
  judge(ni, 2);
}

int  main(){
  int i, j, k, n, x, y;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
      A[i][j] = 0;
    ans[i][0] = i+1;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d", &x, &y);
    for(j=0; j<y; j++){
      scanf("%d", &k);
      A[i][k-1] = 1;
    }
  }
  
  judge(0, 1);
  
  for(i=0; i<n; i++){
    if(A[0][i] == 1){
      judge(i, 1);
      serch(A, i, n);
    }
  }
  judge(0, 2);
  
  for(i=0; i<n; i++){
    for(j=0; j<3; j++){
      if(j>0)
        printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

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

int N;
int a[110][110]={{0}};
int d[110][5]={{0}};
int T=1;

void dfs(int cur);

int main(){
        cin >> N;
        for(int i=0; i<N; i++){
                int v,n;
                cin >> v;
                cin >> n;
                for(int j=0; j<n; j++){
                        int V;
                        cin >> V;
                        a[v-1][V-1]=1;
                }
        }
        dfs(1);
        for(int i=0; i<N; i++){
                cout << i+1 << " ";
                for(int j=0; j<2; j++){
                        cout << d[i][j];
                        if(!j)cout << " ";
                }
        cout << endl;
        }
}


void dfs(int cur){
        d[cur-1][0]=T;
        T++;
        //cerr << "visiting_" << cur << " " << T << endl;
        for(int i=0; i<N; i++){
                if(a[cur-1][i] && !d[i][0]){
                        dfs(i+1);
                }
        }
        d[cur-1][1]=T;
        T++;
        if(cur>1)cur--;
}