Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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


int f[MAX];
int c=0;
int col[MAX];
int depth[MAX];



int dfs[MAX][MAX];
int k[MAX];



void dfsvisit(int u)
{
  int i;
  col[u] = GRAY;
 


depth[u] =  c++;
  for(i = 0;i < k[u]; i++)
    {
      if(col[dfs[u][i]] == WHITE)
    {
     

      dfsvisit(dfs[u][i]);
   

    }
    }
  col[u] = BLACK;
  f[u] = c++;
}

 







int main(){
int n,i=0;
  
 
 
  for(i=0;i<101;i++)
    {
      col[i] = WHITE;
} 




int j;
int tmp;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++)
    {
      scanf("%d",&tmp);

      scanf("%d",&k[i]);

      for(j = 0;j < k[i]; j++)
    {
      scanf("%d",&dfs[i][j]);
    }
    }
  
  for(i = 1;i <= n; i++){
      if(col[i] == WHITE){
     

dfsvisit(i);
    }
    }
  for(j = 1;j <= n; j++)
    {
      /*出力が合わないので補正*/
      printf("%d %d %d\n",j,depth[j]+1,f[j]+1);
    }
 
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[101][101],start[101],end[101],n,p=0,v[101];
void dfs(int u){
	if(!v[u]){v[u]++;
	start[u]=++p;
	r(i,1,n+1)if(a[u][i])dfs(i);
	end[u]=++p;}
}
int main(){
	int q,qq,qqq;
	cin>>n;
	r(i,0,n){cin>>q>>qq;
		r(i,0,qq){cin>>qqq;
			a[q][qqq]++;
		}
	}
	r(i,1,n+1)if(!v[i])dfs(1);
	r(i,1,n+1)cout<<i<<' '<<start[i]<<' '<<end[i]<<endl;
}

C++: #include<stdio.h>
//#include<cstdlib>
// 0オリジンなことに注意！！！

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

int n, M[MAX][MAX];
int color[MAX], d[MAX], f[MAX], time = 0; // d : discovered time  f : finishing time

void dfs_visit(int u){
    int i;
    
    color[u] = GRAY;
    //printf("%d is discovered\n", u+1);
    d[u] = ++time;
    
    for (i = 0; i < n; i++) {
        if(M[u][i] == 1){ // uの隣にiがあったら
            if (color[i] == WHITE) { // 未探索なら
                dfs_visit(i);
            }
        }
    }
    color[u] = BLACK;
    //printf("%d is finishing\n", u+1);
    f[u] = ++time;
}

void dfs(){
    int u, i;
    // init
    for (u = 0; u < n; u++) {
        color[u] = WHITE;
    }
    
    for (u = 0; u < n; u++) {
        if(color[u] == WHITE){
            dfs_visit(u);
        }
    }
    
    for (i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}


int main(){
    int i, j, m, a;
    
    scanf("%d", &n);
    // init
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    // read
    for(i = 0; i < n; i++){
        scanf("%d %d", &m, &m); // First m is dammy
        for(j = 0; j < m; j++){
            scanf("%d", &a);
            M[i][a-1] = 1;
        }
    }
#ifdef D
    // どういう風にグラフが格納されてるか見る
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            printf("%d ", M[i][j]);
        }
        printf("\n");
    }
#endif
    
    dfs();
    
    return 0;
}

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

//次の点へ移動とかする関数
int next_point(int point, int (&a)[100][100], int (&num)[100], int (&back)[100], int time[100][2]){
	int next = a[point][num[point]]-1;
	
	//行先が探索終了しているしている場合、pointを返す
	if(a[next][1] == 0 && time[next][1] != 0){
		a[point][1] -= 1;
		return point;
	}
	
	back[next] = point;
	a[point][1] -= 1;
	return next;
}

int main(void){
	int a[100][100];
	int back[100];				//back[]:現在いる点の始点
	int time[100][2];	//time[i][0]:発見時刻,time[i][1]:探索終了時間
	int bre=0, m, time_now=1, point=0;	//point:現在探索している点
	int num[100];
	
	cin >> m;
	
	for(int i=0; i<m;i++){
		cin >> a[i][0];
		cin >> a[i][1];
		
		for(int j=2; j<a[i][1]+2; j++){
			cin >> a[i][j];
		}
	}

	//ここまで入力
	//ここから↓
	
	//numを2に初期化,time[i][0]をINT_MAXに初期化
	for(int i=0; i<100; i++){
		num[i] = 2;
		time[i][0] = INT_MAX;
	}
	
	time[point][0] = time_now++;
	
	int k=0;
	
	for(int i=0; i<100; i++){
		if(time[point][1] == 0){
			while(time[i][1] == 0){
				
				//矢印が出ていない場合
				if(a[point][1] == 0){
					time[point][1] = time_now++;	//探索終了時刻を決定
					point = back[point];	//始点へ移動
				}
				
				//矢印が出ている場合
				if(a[point][1] != 0){
					point = next_point(point, a, num, back, time);
					num[back[point]] += 1;
					if(time[point][0] > time_now) time[point][0] = time_now++;	//探索開始時刻を決定
				}
			}
			
		}
	}
	
	//出力
	for(int i=0; i<m; i++){
		cout << i+1 << " " << time[i][0] << " " << time[i][1] << "\n";
	}
	
	return 0;
}

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

int a[101][101];
int n = 0;
int found[101];
int ended[101];
int aaa(int i, int time);

int main() {
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
	  a[i][j] = 0;
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
	for (int j = 0; j < k; j++) {
	  cin >> v;
	  a[u][v] = 1;
	  }
	 }
int time = 0;
for (int i = 0; i < 101; i++){
  found[i] = 0;
  ended[i] = 0;
  }
for (int i = 0; i < n+1; i++) {
  if(found[i] > 0)
    continue;
  time++;
  found[i]=time;
  time=aaa(i,time);
  ended[i]=time;
  }
  
for (int i = 1; i < n+1; i++) 
 cout << i << ' ' << found[i] << ' ' << ended[i] << endl;
}
 
int aaa(int i, int time) {
  for (int k = 1; k < n+1; k++) {
    if (a[i][k] == 1 && found[k] == 0) {
	  time++;
	  found[k] = time;
	  time = aaa(k,time);
	  ended[k] = time;
	  }
	 }
	time++;
	return time;
	}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

typedef struct edge_def {
  int from;
  int to;
  int cost;

  edge_def(int _from, int _to, int _cost) {
    from = _from;
    to   = _to;
    cost = _cost;
  }
} edge;

const int V = 100;
int n, t;
vector<edge> es[V];
int d[V], f[V];

void dfs(int v) {
  int i;
  d[v] = ++t;
  for (i=0; i<(int)es[v].size(); i++) {
    int to = es[v][i].to;
    if (d[to] == -1) dfs(to);
  }
  f[v] = ++t;
}

int main() {
  int i, j;
  memset(d, 0xff, sizeof(d));
  memset(f, 0, sizeof(f));
  for (i=0; i<V; i++) es[i].clear();

  scanf("%d ", &n);
  for (i=0; i<n; i++) {
    int u, v, k;
    scanf("%d ", &u);
    scanf("%d ", &k);
    for (j=0; j<k; j++) {
      scanf("%d ", &v);
      es[u-1].psb(edge(u-1, v-1, 0));
    }
  }

  t = 0;
  dfs(0);

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

	return 0;
}