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

static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;
int color[N],nt[N];
int mp[N][N];
int n,d[N],f[N],tt;
int next(int r){
    
    for(int i=nt[r];i<n;i++){
        nt[r]=i+1;
        if(mp[r][i])return i;
        
    }
    return -1;
    
}

void dfs_visit(int r){
    rep(i,n){nt[i]=0;}
    stack<int> s;
    s.push(r);
    d[r]=++tt;
    color[r]=gray;
    while(!s.empty()){
        int u=s.top();
        int v=next(u);
        if(u!=-1){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
        }else{
            f[u]=++tt;
            color[u]=black;
            s.pop();
        }
        
        
        
    }
    
    
}



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


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

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

std::vector<pair<int, int> > stamp(101);
std::vector<std::vector<int> > v(101);
bool isCheckd[101];
int cnt = 0;

void dfs(int k){
	cnt++;
	isCheckd[k] = true;
	stamp[k].first = cnt;
	for(int i=0;i<v[k].size();i++){
		int next = v[k][i];
		if(!isCheckd[next]){
			dfs(next);
		}
	}
	cnt++;
	stamp[k].second = cnt;
}

int main(){
	int n;

	fill(isCheckd,isCheckd+101,false);
	isCheckd[0] = true;
	cin >> n;

	for(int i=0;i<n;i++){
		int u,k;
		cin >> u >> k;
		for(int j=0;j<k;j++){
			int in;
			cin >> in;
			v[u].push_back(in);
		}
	}

	dfs(1);

	for(int i=0;i<n;i++){
		cout << i+1 <<" "<< stamp[i+1].first <<" " <<stamp[i+1].second<< endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int time = 0;

void dfs(int cur, vector<vector <int> > &list, vector<int> &d, vector<int> &f) {
		d[cur] =time;
		time +=1;
    for(int i = 0; i < list.size();i++){
      vector<int>::iterator it = list[cur].end();
	  vector<int>::iterator hoge = find(list[cur].begin(),list[cur].end(),i);
      if(d[i] == 0 && (hoge != it ) ){
        dfs(i,list,d,f);
      }
    }
    f[cur] = time;
    time +=1;
}

int main() {
  int np;
  int k,t,x;
  cin >> np ;
 
  vector <vector <int> > list(np);
  for(int i = 0;i<np;i++) {
    cin >> k;
    cin >> t;
    for(int j = 0; j < t ;j++) {
      cin >>x;
      list[k-1].push_back(x-1);
    }
  }
  vector <int> d(np,0);
  vector <int> f(np,0);
  dfs(0,list,d,f);
  for(int i = 0;i < np; i++){
    cout << i+1 <<" "<<d[i]+1 <<" "<<f[i]+1<<endl;
  }


  return 0;
}

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

struct status{
    int idx_node;
    vector<int> children;
    int finded = 0;
    int visited = 0;
};

int step = 0;
vector<status> graph;

void dfs(int now_node){
    ++step;
    graph[now_node-1].finded = step;
    for(auto&& next_node:graph[now_node-1].children){
        if(not graph[next_node-1].finded){
            dfs(next_node);
        }
    }
    ++step;
    graph[now_node-1].visited = step;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);

    //stdi
    int nb_nodes; cin >> nb_nodes;
    graph.resize(nb_nodes);
    for(auto& times:graph){
        int idx_node; cin >> idx_node; graph[idx_node-1].idx_node = idx_node;
        int nb_edges; cin >> nb_edges; graph[idx_node-1].children.resize(nb_edges);
        for(auto& a:graph[idx_node-1].children){
            cin >> a;
        }
        sort(graph[idx_node-1].children.begin(),graph[idx_node-1].children.end());
    }
    
    //dfs
    int root = 1;
    dfs(root);
    
    //stdo
    for(auto& a:graph){
        cout<<a.idx_node<<" "
            <<a.finded<<" "
            <<a.visited<<"\n";
    }
}

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

int n;
vector<vector<int> > A;
vector<vector<int> > T;
int timer = 0;

void dfs(int cur){
    timer += 1;
    T[cur][0] = timer;

    for(int dst = 0; dst < n; ++dst){
        if(A[cur][dst] == 1 && T[dst][0] == -1){
            dfs(dst);
        }
    }
    timer += 1;
    T[cur][1] = timer;
}

int main(){
    cin >> n;
    A = vector<vector<int> >(n, vector<int>(n, 0));
    T = vector<vector<int> >(n, vector<int>(2, -1));
    for(int i=0; i<n; ++i){
        int k;
        cin >> k;
        k -= 1;
        int u;
        cin >> u;
        for(int j=0; j<u; ++j){
            int v;
            cin >> v;
            v -= 1;
            A[k][v] = 1;
        }
    }
    for(int i=0; i<n; ++i){
        if(T[i][0] == -1){
          dfs(i);
        }
    }
    for(int i=0; i<n; ++i){
        cout << i+1 << " " << T[i][0] << " " << T[i][1] << endl;
    }
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for ( v = 0; v < n; v++){
        if ( M[u][v] == 0) {
            continue;
        }
        if (color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for ( u = 0; u < n; u++) {
        color[u] = WHITE;
    }
    tt = 0;
    for (u = 0; u < n; u++) {
        if ( color[u] == WHITE ) {
            dfs_visit(u);
        }
    }

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

int main() {
    int u, v, k, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++){
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    return 0;
}