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>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++(i))
#define REP(i,n) FOR(i,0,n)

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

using namespace std;
typedef vector<vector<int>> VVI;

VVI mat;
vector<int> d,f,color;
int tt,n;

void dfs_visit(int i){
  int v;
  color[i] = 1;
  d[i]=++tt;
  REP(v,n){
    if(mat[i][v]==0) continue;
    if(color[v]==0){
      dfs_visit(v);
    }
  }
  color[i] = 2;
  f[i] = ++tt;
}
void dfs(int n){
  tt=0;

  int i;
  REP(i,n){
    if(color[i]==0) dfs_visit(i);
  }

  REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;
}

int main(void){
  int q,k,i,l;
  cin >> n;
  mat=VVI(n, vector<int>(n));
  color=d=f=vector<int>(n);
  REP(i,n){
    cin >> l; l--;
    cin >> q;
    REP(j,q){
      cin >> k; k--;
      mat[l][k]=1;
    }
  }
  dfs(n);

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,t;
int d[100],f[100];
bool graph[100][100], visited[100];

void dfs(int v){
    visited[v]=true;
    t++;
    d[v]=t;

    for(int v2=0; v2<n; v2++){
        if(graph[v][v2] && visited[v2]==false) dfs(v2);
    }

    t++;
    f[v]=t;
}

int main(void){
    cin >> n;
    t=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            graph[i][j]=false;
        }
    }
    for(int i=0; i<n; i++){
        int v,k; cin >> v >> k;
        for(int j=0; j<k; j++){
            int w; cin >> w;
            graph[v-1][w-1]=true;
        }
    }

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


}

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

struct StSeq
{
  int m_nBgn;
  int m_nEnd;

  StSeq() : m_nBgn(0), m_nEnd(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StSeq>& rvoDFSrch)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvvnAdjcy.resize(nMaxSiz + 1, vector<int>(nMaxSiz + 1, 0));
  for (int i = 0; i < nMaxSiz; ++i)
  {
    int nx, nSecSiz;
    cin >> nx >> nSecSiz;
    for (int j = 0; j < nSecSiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StSeq oSeq;
  rvoDFSrch.resize(nMaxSiz + 1, oSeq);
}

void fnDepthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, vector<StSeq>& rvoDFSrch, int nKey)
{
  static int stnCnt = 0;

  if (rvoDFSrch[nKey].m_nBgn == 0)
    rvoDFSrch[nKey].m_nBgn = ++stnCnt;

  for (int j = 1; j < cnrvvnAdjcy.size(); ++j)
    if (cnrvvnAdjcy[nKey][j] == 1)
      fnDepthFirstSearch(cnrvvnAdjcy, rvoDFSrch, j);

  if (rvoDFSrch[nKey].m_nEnd == 0)
    rvoDFSrch[nKey].m_nEnd = ++stnCnt;
}

void fnResult(const vector<StSeq>& cnrvoDFSrch)
{
  for (int i = 1; i < cnrvoDFSrch.size(); ++i)
    cout << i <<  " " << cnrvoDFSrch[i].m_nBgn << " " << cnrvoDFSrch[i].m_nEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  vector<StSeq> voDFSrch;

  fnInput(vvnAdjcy, voDFSrch);
  fnDepthFirstSearch(vvnAdjcy, voDFSrch, 1);
  fnResult(voDFSrch);

  return 0;
}

C++: #include<stdio.h>
#include<stack>
using namespace std;
int tu[1000][1000];
int a[10000];
int an[10000];
int d[10000];
int f[10000];
int shijian,n;
int next(int q){
for(int i=an[q];i<n;i++){
    an[q]=i+1;
    if(tu[q][i])return i;
}
return -1;
}
void sou(int u){
     stack<int > s;
     s.push(u);
     a[u]=2;
     d[u]=++shijian;
     while(!s.empty()){
        int x=s.top();
        int v=next(x);
        if(v!=-1){
            if(a[v]==1){
                a[v]=2;
                d[v]=++shijian;
                s.push(v);
            }
        }
        else {
            s.pop();
            a[x]=3;
            f[x]=++shijian;
        }
     }
}
void shensou(){
     for(int u=0;u<n;u++){
        a[u]=1;
        an[u]=0;
     }
     shijian=0;
     for(int u=0;u<n;u++){
        if(a[u]==1)sou(u);
     }
     for(int u=0;u<n;u++){
         printf("%d %d %d\n",u+1,d[u],f[u]);
     }
}


int main(){
   int v;
   int m;
   int x;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
        scanf("%d%d",&v,&m);
        v--;
        for(int j=0;j<m;j++){
            scanf("%d",&x);
            x--;
            tu[v][x]=1;
        }
   }
   shensou();
return 0;
}

C++: #include<iostream>
using namespace std;
int M[100][100] = {};
int color[100] = {};
int d[100] = {}, f[100] = {};
int cot=0;
int n;

void dps(int u) {
	if (color[u] == 0) {
		cot++;
		d[u] = cot;
		color[u]++;
	}

	for (int t = 0;t < n;t++) {
		if (M[u][t] == 1) {
			if(color[t]==0){
			    dps(t);
			}
			
			
		}
	}
	if (color[u] == 1) {
        cot++;
	    f[u] = cot;
		color[u]++;
	}
	
	return;

}
int main(){
	int k,m,j;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> m>>k;
		for (int l = 0;l < k;l++) {
			cin >> j;
			M[m - 1][j - 1] = 1;
		}
	}
	for (int i = 0;i < n;i++) {
		if (color[i] == 0) {
			dps(i);
		}
	}


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

	return 0;
}

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

enum Status {WHITE, GRAY, BLACK};

stack<int> stc;
Status *status;
int *discovered, *finished;
vector<vector<int> > a;
int n, timer;

void dfs(int i){
        if(status[i]==BLACK) return;
        if(status[i]==WHITE){
                discovered[i] = ++timer;
                status[i] = GRAY;
        }
        stc.push(i);

        for(int j=0;j<a[i].size();j++) dfs(a[i][j]);

        if(status[i]==GRAY){
                finished[i] = ++timer;
                status[i] = BLACK;
        }
        stc.pop();
}

int main(){

        cin>>n;
        a = vector<vector<int> >(n, vector<int>());
        status = new Status[n];
        discovered = new int[n];
        finished = new int[n];

        int m, k, r;
        for(int i=0;i<n;i++){
                cin>>r;
                cin>>m;
                for(int j=0;j<m;j++){
                        cin>>k;
                        a[r-1].emplace_back(k-1);
                }
        }
        for(int i=0;i<n;i++) status[i] = WHITE;

        timer = 0;
        dfs(0);


        for(int i=0;i<n;i++){
                cout<<i+1<<" "<<discovered[i]<<" "<<finished[i]<<endl;
        }
        return 0;
}