Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include<stdio.h>

void dfs_visit(int);
void dfs();

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],D[N],F[N],t;

int main()
{
  int i,j,u,x,y;

  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",&u,&y);
      u--;
      for(j=0;j<y;j++)
        {
          scanf("%d",&x);
          x--;
          M[u][x]=1;
        }
    }

  dfs();

  return 0;
}

void dfs_visit(int u)
{
  int v;
  color[u]=GRAY;
  D[u]=++t;

  for(v=0;v<n;v++)
    {
      if(M[u][v]==0) continue;
      if(color[v]==WHITE)
        {
          dfs_visit(v);
        }
    }
  color[u]=BLACK;
  F[u]=++t;
}

void dfs()
{
  int u;

  for(u=0;u<n;u++)
    color[u]=WHITE;

  t=0;

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

  for(u=0;u<n;u++)
    printf("%d %d %d\n",u+1,D[u],F[u]);
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

int n;
int M[110][110];
int visited[110];
vector<int> d(110, 0);
vector<int> f(110, 0);
int t;

void dfs(int v){
    
    t++;
    d[v] += t;
    visited[v] = 1;
    
    for (int i = 0; i < n; i++){
        if (M[v][i] == 0) continue;
        
        if(visited[i] == 0) dfs(i);
    }
    
    visited[v] = 2;
    t++;
    f[v] += t;
}

int main(){
    cin >> n;
    t = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) M[i][j] = 0;
        visited[i] = 0;
    }
    
    for (int i = 0; i < n; i++){
        int u;
        cin >> u;
        u--;
        
        int k;
        cin >> k;
        
        for (int j = 0; j < k; j++){
            int v;
            cin >> v;
            v--;
            
            M[u][v]++;
        }
    }
    
    for (int i = 0; i < n; i++){
        if (visited[i] == 0) dfs(i);
    }
    
    for (int i = 0; i < n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    
}

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

vector<vector<int> > list(100);
vector<vector<int> > timed(100);
int times;
void dfs(int now){
	if(!timed[now].empty())	return;
	timed[now].push_back(times++);
	for(int i=0;i<(int)list[now].size();i++){
		dfs(list[now][i]);
	}
	timed[now].push_back(times++);
}

int main(){
	int n;	cin>>n;
	int id,num,ne;
	for(int i=0;i<n;i++){
		cin>>id>>num;
		id--;
		for(int j=0;j<num;j++){
			cin>>ne;
			list[id].push_back(ne-1);
		}
	}
	times=1;
	for(int i=0;i<n;i++){
		if(timed[i].empty())	dfs(i);
	}
	for(int i=0;i<n;i++){
		cout<<i+1;
		for(int j=0;j<(int)timed[i].size();j++){
			cout<<" "<<timed[i][j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
int n;
int m[N][N];
int used[N];
int time = 1;
int bb_start[N];
int bb_end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    bb_start[root] = time++;
    stack<int> s;
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            bb_start[v] = time++;
            s.push(v);
        } else{
            bb_end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, bb_start[i], bb_end[i]);
    }
    return 0;
}

C++: #include <stdio.h>
#define MAX 101

int n, ni = 1;
int A[MAX][MAX] = {0}, a[MAX] = {0}, b[MAX] = {0};

void serch(int x){
  int i;
  
  a[x] = ni++;
  for(i=1; i<=n; i++){
    if(a[i] == 0 && A[x][i] == 1)
      serch(i);
  }
  b[x] = ni++;
}

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

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int timer = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	timer++;
	a[t].t = timer;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	timer++;
	a[t].e = timer;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n, vector<int> & u){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            if(u[i] == 0){
                u[i] = 1;
                dfs(A, B, i, n, u);
            }
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    vector<int> u(n, 0);
    u[0] = 1;
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n, u);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != 2) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}