Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

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

static const int N = 100;
int n,color[N],M[N][N],d[N],f[N];
int t;

void dfs_visit(int u){
  int v;
  color[u] = 1;
  d[u] = ++t;
  for (v = 0; v < n; v++) {
    if(M[u][v] == 0) continue;
    if(color[v] == 0) dfs_visit(v);
  }
  color[u] = 2;
  f[u] = ++t;
}
void dfs(){
  int u;

  for (u = 0; u < n; u++) {
    color[u] = 0;
  }
  t = 0;

  for (u = 0; u < n; u++) {
    if(color[u] == 0) dfs_visit(u);
  }

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

int main() {
  int i,j,u,k,v;

  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  //cout << "done1" << endl;

  dfs();

  return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<vector<int> > arr(n);
    vector<int> tmparr;
    int u, k;
    int tmp;
    for(int i=0;i<n;++i){
        cin>>u>>k;
        u--;
        tmparr.clear();
        for(int j=0;j<k;++j){
            cin>>tmp;
            tmp--;
            tmparr.push_back(tmp);
        }
        arr[u] = tmparr;
    }
    stack<int> stack;
    stack.push(0);
    map<int, int> used;
    map<int, int> owari;
    map<int, pair<int, int> > ans;
    int state;
    int time = 1;
    while(!stack.empty()){
        while(!stack.empty()){
            state = stack.top();
            if(used[state]>0){
                if(owari[state]==0){
                    ans[state].second = time;
                    owari[state]++;
                    time++;
                }
                stack.pop();
            }
            else {
                ans[state].first = time;
                time++;
            }
            used[state]++;
            for(int i=arr[state].size()-1;i>=0;--i){
                if(used[arr[state][i]]==0){
                    stack.push(arr[state][i]);
                }
            }
        }
        for(int i=0;i<n;++i){
            if(used[i]==0){
                stack.push(i);
                break;
            }
        }
    }
    for(int i=0;i<n;++i){
        cout<<i+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int searchAll(vertex *array, int (*A)[101], int n){
    int time = 0;
    for(int id=1;id<=n;id++){
        if(!array[id].found){
            time=search(array,A,id,n,time);
            printf("%d\n",time);
        }
    }
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = searchAll(array, A, n);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<int> G[1000000];
int st[1000000];
int en[1000000];
int t;

void DFS(int n) {
    t++;
    st[n] = t;
    int s = G[n].size();
    for (int i = 0; i < s; i++) {
        if (st[G[n][i]] == intmax) {
            DFS(G[n][i]);
        }
    }
    t++;
    en[n] = t;
}

int main() {
    int N;
    cin >> N;
    V = N;
    fill(st, st + V + 10, intmax);
    fill(en, en + V + 10, intmax);
    t = 0;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int n;
            cin >> n;
            G[i].push_back(n - 1);
        }
    }
    for (int i = 0; i < N; i++) {
        if (st[i] == intmax) {
            DFS(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << st[i] << " " << en[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int d[111],f[111],G[111][111],t=1,n;
int dfs(int now){
  d[now]=t++;
  for(int i=1;i<=n;i++)
    if(G[now][i]&&d[i]==0)dfs(i);
  f[now]=t++;
}

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    int v2,v1,k;
    scanf("%d%d",&v1,&k);
    for(int j=0;j<k;j++){
      scanf("%d",&v2);
      G[v1][v2]=1;
    }
  }
  for(int i=1;i<=n;i++)if(d[i]==0)dfs(i);
  for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
  
  return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,d[N],f[N],tt;
int color[N],nt[N];
int mp[N][N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(mp[u][v]!=0)return v;
    }
    return -1;
}


void dfs_visit(int r){
    
    rep(i,n)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){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;nt[i]=0;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}