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)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	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<iostream>
using namespace std;
#include<stdio.h>

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &e);
        for(j = 1; j <= e; j++){
            scanf("%d", &b); G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

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

C++: #include <bits/stdc++.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;
 
void visit(int u) {
  int i,j,v;
  T++;  
  d[u] = T;
 
  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }
   
  T++;
  F[u] = T;
 
}
 
 
 
int main() {
   
   
  int i,j,k,l,u,a,t;
 
  for(i=0;i<n;i++) d[i] = 0;
 
  scanf("%d",&n);
 
  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;
 
    }
 
  for(i=0;i<n;i++){
 
    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);
 
    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visit (i);
  }
     
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;
 
     
     
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
vector<pair<int,int> > ans(100);
vector<vector<int> > da(100);
vector<bool> ju(100,false);

void dfs(int m,int &ti){
    bool ch=true;
    for(int i=0;i<da[m].size();i++){
        if(!ju[da[m][i]]){
            ju[da[m][i]]=true;
            ch=false;
            ti++;
            ans[da[m][i]].first=ti;
            dfs(da[m][i],ti);
        }
    }
    ti++;
    ans[m].second=ti;
}

int main(){
    int n,ti=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        int y;
        cin >> y;
        vector<int> iin(y);
        for(int j=0;j<y;j++){
            cin >>iin[j];
            iin[j]--;
        }
        da[x-1]=iin;
    }
    for(int i=0;i<n;i++){
        if(!ju[i]){
            ju[i]=true;
            ti++;
            ans[i].first=ti;
            dfs(i,ti);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << ' ' << ans[i].first << ' ' << ans[i].second << endl; 
    }
}

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

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

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

void dfs_visit(int r) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(r);
	color[r] = BLACK;
	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() {
	for(int i = 0; i < n; i++){
		color[i] = WHITE; nt[i] = 0;
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	for(int i =0; i < n; i++ ) {
    	cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}


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

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>


using namespace std;

int N;
int D[100+10] = {};
int U = 0;
int K[100+10] = {0};
int V = -1;
int G[100+10][100+10] = {0};
int curtime_st[100+10] = {0};
int curtime_en[100+10] = {0};



//stack dst   queue bfs


int time_ = 1;
int prev1 = 0;
int prev_b = 0;
void dfs(int cur){
  if (cur == -1)return;//??¢??±
  if (curtime_st[cur] == 0)curtime_st[cur] = time_;

  D[cur] = 0;
  time_ += 1;
  //
  //cerr << "visiting " << cur << " " << time_ - 1  << endl;
  
  for(int dst=1;dst<=N;++dst){
    if(D[dst] == -1 && G[cur][dst] == 1){
      dfs(dst);
	}
  }
  if(curtime_en[cur] == 0 || curtime_en[cur] == curtime_st[cur])curtime_en[cur] = time_;
  time_ += 1;
  return;
}







int main(){
  cin >> N;

  for(int i=0;i<101;++i){
    D[i] = -1;//?????????
  }

  for(int i=0;i<N;++i){
    cin >> U;
    cin >> K[U];
    for(int j=0;j<K[U];++j){
      cin >> V;
      G[U][V] = 1;
    }
  }

  for(int j=1;j<=N;++j){
    for(int i=1;i<=N;++i){
      //cout << G[i][j] << " ";
    }
    //cout << endl;
  }

  dfs(1);
  for(int i=2;i<=N;++i){
    if(D[i] == -1)dfs(i);
  }

  for(int i=1;i<=N;++i){
    cout << i << " " << curtime_st[i] << " " << curtime_en[i] << endl; 
  }
}

C++: #include <iostream>

using namespace std;

int graph[101][101]={};
int d[101]={};
int f[101]={};
int n,v,k,time1 = 0,sw[101] = {};


void dfs1(int u){

  sw[u] = 1;
  d[u] = ++time1;

  for(int i = 1; i <= n; i++){
    if( graph[u][i] == 1 && sw[i] == 0 ){
     dfs1(i);
    }

  }
    f[u] = ++time1;
}


int main(){
  int u;
  cin >> n ;
  //グラフをつくる
  for(int i = 0; i < n; i++){
    cin >> u >> k ;
    for(int j = 0; j < k ; j++){
      cin >> v;
      graph[u][v] = 1;
    }
  }
 
 for(int i = 1; i <= n; i++){
    if(sw[i] == 0){
      dfs1(i);
	}
  }

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

  }
}