Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

int n;
vector<int> d, f;
vector<vector<int>> g;
int Time = 0;
void dfs(int v){
  d[v] = ++Time;
  REP(i, g[v].size()){
    int nv = g[v][i];
    if(d[nv] != -1) continue;
    dfs(nv);
  }
  f[v] = ++Time;
}

int main(){
  cin >> n;
  d.resize(n,-1), f.resize(n), g.resize(n);
  REP(i, n){
    int u, k;
    cin >> u >> k;
    g[i].resize(k);
    REP(j, k){
      cin >> g[i][j];
      g[i][j]--;
    }
  }
  REP(i, n){
    if(d[i] == -1){
      dfs(i);
    }
  }
  REP(i, n){
    cout << i+1 << " " << d[i] <<" " <<  f[i] << endl;
  }
  return 0;
}

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

using namespace std;

const int WHITE=0, GRAY=1, BLACK=2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> discover;
    vector<int> finish;
    vector<int> state;
    int time = 1;
    
    DFS(int n):n(n) {
        g.assign(n, vector<int>());
        discover.assign(n, -1);
        finish.assign(n, -1);
        state.assign(n, WHITE);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (state[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        discover[u] = time++;
        for (int v : g[u]) {
            if (state[v] == WHITE) {
                state[v] = GRAY;
                dfs(v);
            } 
        }
        finish[u] = time++;
        state[u] = BLACK;
    }
    
    void print() {
        for (int i = 0; i < n; i++) {
            cout << i << ":";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    DFS dfs(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--;
           dfs.addEdge(u, v);
       }
    }
    
    //dfs.print();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) <<  " " << dfs.discover[i] << " " << dfs.finish[i] << endl; 
    }
    
    return 0;
}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        int j = 0;
        for (; j < n-1; ++j) {
            cout << A[i][j] << " ";
        }
        cout << A[i][j] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stack>

using namespace std;

static const int N = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

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

//按编号顺序获取与u相邻的v
int next(int u) {
    for (int v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v]) return v;
    }
    return -1;
}

void dfs_visit (int r) {
    for (int i = 0; i < n; i++) {
        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) {
            if (color[v] == White) {
                color[v] = Gray;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = Black;
            f[u] = ++tt;
        }
    }
    
}

void dfs() {
    for (int i = 0; i < n; i++) {
        color[i] = White;
        nt[i] = 0;
    }
    tt = 0;
    
    for (int u = 0; u < n; u++) {
        if (color[u] == White) dfs_visit(u);
    }
    for (int i = 0; i < n; i++) {
        cout <<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

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

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0; 
static const int GRAY = 1; 
static const int BLACK = 2; 

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

//用编号顺序获取与U相邻的v 
int next(int u){
	for(int v = nt[u];v < n;v++){
		nt[u] = v + 1;
		if( M[u][v] ){
			return v;
		}
	}
	return -1;
}
//用栈实现的深度优先搜索 
void dfs_visit(int r){
	for(int i = 0;i < n;i++){
		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){
			if(color[v] == WHITE){
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}else{
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs(){
	//初始化 
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;
	
	//以未访问的u为起点进行深度优先搜索 
	for(int u = 0;u < n;u++){
		if(color[u] == WHITE){
			dfs_visit(u);
		}
	}
	for(int i = 0;i < n;i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}
int main(){
	int u,v,k;
	cin >> n;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			M[i][j] = 0;
		}
	}
	
	for(int i = 0;i < n;i++){
		cin >> u >> k;
		u--;
		for(int j = 0;j < k;j++){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	
	dfs();
	
	
	
	return 0;
}

C++: #include <cstring>
#include <iostream>

static int tp = 1;
static int n;

void depth_first(int node, int *start_ts, int *end_ts, int **adj_list) {
    start_ts[node] = tp;
    tp++;
    for (int i = 0; adj_list[node][i] != -1; i++) {
        int dst = adj_list[node][i];
        if (start_ts[dst] != 0) {
            continue;
        }
        depth_first(dst, start_ts, end_ts, adj_list);
    }
    end_ts[node] = tp;
    tp++;
}

int main() {
    std::cin >> n;
    int *adj_list[n];

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

    int start_ts[n], end_ts[n];
    memset(start_ts, 0, sizeof(int) * n);
    for (int i = 0; i < n; i++) {
        if (start_ts[i] == 0) {
            depth_first(i, start_ts, end_ts, adj_list);
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << start_ts[i] << " " << end_ts[i] << std::endl;
    }
}