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>
#include <stack>
#include <cstdio>

static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int NIL=-1;

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
stack<int> S;
int n;
int t=0;

int next(int u){
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1&&color[i]==WHITE) return i;
  }
  return NIL;
}

void dfs(int u){
  S.push(u);
  color[u]=GRAY;
  d[u]=++t;
  while(S.empty()==false){
    u=S.top();
    int v=next(u);
    if(v!=NIL){
      color[v]=GRAY;
      d[v]=++t;
      S.push(v);
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  for(int i=1;i<=n;i++){
    if(color[i]==WHITE) dfs(i);
  }
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

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 n;
//?????\??????
int M[N][N];
//??°?????¶???????¢????
int color[N];
//??\??¶????????°??¶???
int d[N];
//??\??¶???????????¶???
int f[N];
//??¶???
int tt;
//???????????????????????????????????????
//?????¨?????????????????¨????????\??????????????????
int nt[N];

//????????????????????????u?????????v
int next(int u){
    for(int v=0;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]=GRAY;
    //?????°??¶???
    d[r]=++tt;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1&&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++)
        nt[i]=0,color[i]=WHITE;
    tt=0;

    //??\????????????u?????????????????±?????????????´¢
    for(int u=0;u<n;u++)
        if(color[u]==WHITE)
            dfs_visit(u);

    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 j=0;j<k;j++){
            cin>>v;v--;
            M[u][v]=1;
        }
    }

    dfs();
}

C++: #include<iostream>
using namespace std;
int n,M[101][101];
int visit[101],d[101],f[101],t;
const int WHITE=0;//未訪問
const int BLACK=1;//訪問した

void dfs(int u){
  visit[u]=BLACK;//訪問はした
  d[u]=++t;//発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue;//辺がない
    if(visit[v]==WHITE){//訪問していない
      dfs(v);//vを始点として探索
    }
  }
  f[u]=++t;//訪問完了時刻
}



int main(){
  int u,v,k;
  cin>>n;

  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }

 
 
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE){//訪問していないか
      dfs(i);
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }

  
  return 0;
}

C++: #include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

int n;
vector<vector<bool>> M(100, vector<bool>(100));
vector<int> C(100), d(100), f(100), nt(100);
int tt;

int next(int u) {
	for (int i = nt.at(u); i < n; i++) {
		nt.at(u) = i + 1;
		if (M.at(u).at(i)) return i;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt.at(i) = 0;

	stack<int> S;
	S.push(r);
	C.at(r) = 1;
	d.at(r) = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);

		if (v != -1) {
			if (C.at(v) == 0) {
				C.at(v) = 1;
				d.at(v) = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			C.at(u) = 2;
			f.at(u) = ++tt;
		}
	}
}

void dfs() {
	for (int i = 0; i < n; i++) {
		C.at(i) = 0;
		nt.at(i) = 0;
	}
	tt = 0;

	for (int i = 0; i < n; i++) {
		if (C.at(i) == 0) dfs_visit(i);
	}

	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
	}
}

int main() {
	int u, k, v;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v >> k;

		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			M.at(v - 1).at(x - 1) = true;
		}
	}

	dfs();

	return 0;
}

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

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
//---------------------------------------------------------------

using vi = vector<int>;
void dfs(int src, Matrix &M, vi &time_s, vi &time_t, int &time) {
    int n = M.size();
    time_s[src] = time++;
    for (int dst = 0; dst < n; dst++) {
        if (M[src][dst] && time_s[dst] < 0) {
            dfs(dst, M, time_s, time_t, time);
        }
    }
    time_t[src] = time++;
}

int main() {
    int n; cin >> n;
    Matrix M(n, Array(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int v; cin >> v; M[u - 1][v - 1]++;
        }
    }
    vector<int> time_s(n, -1), time_t(n, -1);
    int time = 0;
    for (int i = 0; i < n; i++) if (time_s[i] < 0) {
        dfs(i, M, time_s, time_t, time);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << time_s[i] + 1 << " " << time_t[i] + 1 << endl;
    }
    return 0;
}

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

  dfs1(1);

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

  }
}