Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

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