Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

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

enum Color {
	WHITE,
	GRAY,
	BLACK,
};

class dfs {
public:
	dfs(bool matrixT[][100], Color colorT[], int ts_F[], int ts_L[], int verNum) {
		for (int i = 0; i < verNum; i++) {
			for (int j = 0; j < verNum; j++)
				matrixTable[i][j] = matrixT[i][j];
		}
		verNumber = verNum;
	}

	void DFS(int nowVerVal) {
		colorTable[nowVerVal] = GRAY;
		++ttl;
		ts_first[nowVerVal] = ttl;

		for (int nextVer = 0; nextVer < verNumber; nextVer++) {
			if (matrixTable[nowVerVal][nextVer] == false) continue;
			if (colorTable[nextVer] != WHITE) continue;
			DFS(nextVer);
		}
		colorTable[nowVerVal] = BLACK;
		++ttl;
		ts_last[nowVerVal] = ttl;
	}

	void DFS_Init() {
		ttl = 0;
		for (int i = 0; i < verNumber; i++)
			colorTable[i] = WHITE;

		for (int i = 0; i < verNumber; i++)
			if (colorTable[i] == WHITE) DFS(i);
	}

	void print() {
		for (int i = 0; i < verNumber; i++) {
			cout << i + 1 << " " << ts_first[i] << " " << ts_last[i] << endl;
		}
	}
private:
	bool matrixTable[100][100];
	Color colorTable[100];
	int ts_first[100];
	int ts_last[100];
	int verNumber;
	int ttl;
};

int main() {
	int verNum; //num??????????????°???value????????????????????????????????¨???
	bool matrixTable[100][100]; //???????????¨??????????????????
	Color colorTable[100];
	int timeStamp_first[100];
	int timeStamp_last[100];
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++) {
			matrixTable[i][j] = false;
		}

	for (int i = 0; i < verNum; i++) {
		int verVal, nextVerNum;
		cin >> verVal >> nextVerNum;
		for (int j = 0; j < nextVerNum; j++) {
			int nextVerVal;
			cin >> nextVerVal;
			//0?????????????????´???
			matrixTable[verVal - 1][nextVerVal - 1] = true;
		}
	}

	dfs* d = new dfs(matrixTable, colorTable, timeStamp_first, timeStamp_last, verNum);
	d->DFS_Init();
	d->print();

	return 0;
}

C++: #include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
//   訪問状態     発見    完了
int n,M[101][101];
const int WHITE=0; //未訪問
const int GRAY=1;  //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(int j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) //訪問していないか
      dfs(i); //iを始点に
  }
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int tim;
int n;
void visit(int);

int main(){
	tim=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1;
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1;
		}
	}
	visit(0);
	// ??¨???????????????????????????????????°?¨????????????¨??????
	for(i=0;i<n;i++){
		cout<< i+1 << " "<<d[i]<< " "<<f[i];
		cout<<endl;
	}
	return 0;
}

void visit(int k){
	int i;
	d[k]=++tim;
	for(i=0;i<n && f[k]==-1;i++){
		if(map[k][i]==1&&d[i]==-1){
			visit(i);
		}
	}
	f[k]=++tim;
}

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

using namespace std;
using ll = long long;


int n;
vector<vector<int>> hen;
vector<int> in, out;
vector<bool> seen;

void dfs(int cur, int& tim)
{
    tim++;
    in[cur] = tim;
    seen[cur] = true;
    for(auto i : hen[cur])
    {
        if(seen[i])continue;
        dfs(i, tim);
    }
    tim++;
    out[cur] = tim;
}


int main()
{
    cin >> n;
    hen.resize(n);
    in.resize(n);
    out.resize(n);
    seen.resize(n);
    for(int i = 0; i < n; i++){
        int u,k;cin >> u >> k; u--;
        for(int j = 0; j < k; j++){
            int v; cin >> v; v--;
            hen[u].push_back(v);
        }
        sort(hen[u].begin(), hen[u].end());
    }

    int t = 0;
    for(int i = 0; i < n; i++){
        if(!seen[i])dfs(i,t);
    }

    for(int i = 0; i < n; i++){
        cout << i + 1 << " " << in[i] << " " << out[i] << endl;
    }
}

C++: #include <iostream>

using namespace std;

#define MAX 100

int n,Time;
int G[MAX][MAX],d[MAX],f[MAX];
bool used[MAX];

void dfs(int v){
  d[v] = Time++;
  used[v] = true;

  for(int i = 0 ; i < n ; i++){
    if(!used[i] && G[v][i]){
      dfs(i);
    }
  }

  f[v] = Time++;
}

int main(){
  cin >> n;

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

  Time = 1;
  for(int i = 0 ; i < n ; i++){
    if(!used[i]){
      dfs(i);
    }
  }

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

  return 0;
}

C++: #include<queue>
#include<stack>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
 
int n, dd[100], f[100], tmap[100][100];
int color[100], t = 1;
stack<int> S;
 
int a(){
    int d = S.top();
    dd[d] = t;
    t++;
    color[d] = 1;

    for (int i = 1; i <= n; i++){
        if (color[i] == 0 && tmap[d][i] == 1){
            S.push(i);
            a();
        }
    }

    f[d] = t;
    t++;
    return 0;
}
 
 
int main(){
    cin >> n;
    for (int i = 0; i < 100; i++){
        dd[i] = f[i] = color[i] = 0;
        for (int j = 0; j < 100; j++){
            tmap[i][j] = 0;
        }
    }
 
    int u, k, v;
 
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v;
            tmap[u][v] = 1;
        }
    }
    for(int i=1;i<=n;i++){
        if(color[i] == 0){
             S.push(i);
             a();
         }
    }
    for (int i = 1; i <= n; i++){
        cout << i << " " << dd[i] << " " << f[i] << endl;
    }
    return 0;
}