Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

#define WHITE 1
#define GRAY 2
#define BLACK 3

int now, n, u, k, v, tree[102][102], timeTable[102][2], color[102], timeNow = 1;
stack<int> st;

void dfs(){
    while(1){
        if(st.empty()){
            FOR(l, 1, n + 1){
                cout << l << " " << timeTable[l][0] << " " << timeTable[l][1] << endl;
            }
            break;
        }else{
            now = st.top();
          	if(color[now] == WHITE){
            	timeTable[now][0] = timeNow;
            }
            color[now] = GRAY;
            int cnt = 1;
            while(1){
                if(cnt == n + 1){
                    st.pop();
                    color[now] = BLACK;
                    timeTable[now][1] = timeNow + 1;
                    break;
                }else if(tree[now][cnt] && color[cnt] == WHITE){
                    st.push(cnt);
                    break;
                }
                cnt++;
            }
            timeNow++;
        }
    }
}

int main(){
    cin >> n;
  	REP(i, 102){
    	REP(j, 102){
        	tree[i][j] = 0;
        }
    }
    REP(i, n){
        cin >> u >> k;
        color[i + 1] = WHITE;
        REP(j, k){
            cin >> v;
            tree[u][v] = 1;
        }
    }
    st.push(1);
    dfs();
}

C++: #include<bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
int N;
vector<int> d;
vector<int> f;
int de = 0;
void dfs(int v,int p){
    d[v] = ++de;
    for(auto nv:G[v]){
        if(d[nv]!=-1) continue;
        dfs(nv,v);
    }
    f[v] = ++de;
}
signed main(){
    stack<int> st;
    cin >> N;
    G.resize(N);
    d.assign(N,-1);
    f.assign(N,-1);
    for(int i=0;i<N;i++){
        int id;cin >> id;
        int k;cin >> k;
        for(int j=0;j<k;j++){
            int a;cin >> a;a--;
            G[i].push_back(a);
        }
    }
    /*st.push(0);
    int dep=0;
    while(!st.empty()){
        int now = st.top();
        dep++;
        d[now] = dep;
        st.pop();
        for(int nv:G[now]){
            if(d[nv]!=-1) continue;
            st.push(nv);
        }
    }*/
    for(int i=0;i<N;i++){
        if(d[i]==-1) dfs(i,-1);
    }
    for(int i=0;i<N;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
int t = 0;

void visit(int u, int *color, int *d, int *f, vector<vector<int>> Adj){
    int zero = 0;
    color[u] = GRAY;
    d[u] = ++t;
    for (int i = 1; i <= Adj[u].size(); i++){
        if (Adj[u][i] == 0){
            break;
        }
        if (color[Adj[u][i]] == WHITE){
            visit(Adj[u][i], color, d, f, Adj);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

int main(int argc, char* argv[]) {
    int n, u, k, v;
    cin >> n;
    n++;
    int color[n], d[n], f[n];
    vector<vector<int>> Adj(n, vector<int>(n, 0));

    for (int i = 1; i <= n; i++) color[i] = WHITE;

    for (int i = 1; i < n; i++){
        cin >> u >> k;
        for (int j = 1; j <= k; j++){
            cin >> v;
            Adj[i][j] = v;
        }
    }

    for (int i = 1; i < n; i++)
        if (color[i] == WHITE)
            visit(i, color, d, f, Adj);

    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<cstdio>
#include<algorithm>
using namespace std;

int timex = 0;

int n;

string *color = new string[n];

int *d = new int[n];

int *f = new int[n];

int c[100][100];

void dfs(int u){
  color[u] = "glay";
  d[u] = ++timex;

  for(int v = 0; v < n; v++){
    if(c[u][v] == 1 && color[v] == "white"){
      dfs(v);
    }
  }

color[u] = "black";
f[u] = ++timex;

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      c[i][j] = 0;
    }
  }

  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      c[i][v - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    color[i] = "white";
  }

  dfs(0);

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




  return 0;
}

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

using namespace std;

int t;
int N;
int d[110], f[110];
vector<vector<int> > adj(110);
void dfs(int cur){
    d[cur] = t;
    t += 1;
    //cerr << "visiting " << cur << " " << t << endl;
    for(int i = 0; i < adj[cur].size(); ++i){
        int dst = adj[cur][i];
        if(d[dst] == 0){
            dfs(dst);
        }
    }
    f[cur] = t;
    t++;
}

int main(){
    cin >> N;
    t = 1;
    int u, k;
    for(int i = 0; i < N; ++i){
        d[i] = 0;
        f[i] = 0;
    }
    for(int i = 0; i < N; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            adj[u].push_back(v);
        }
        sort(adj[u].begin(), adj[u].end());
    }
    for(int i = 1; i < N+1; ++i){
        if(d[i] == 0) dfs(i);
    }
    
    for(int i = 1; i < N+1; ++i){
        cout << 1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

int a[100][100];
int n,p,q,r;
int T[100],F[100];
int Time = 0;
void dfs(int cur) {
	T[cur] = Time;
	Time += 1;
	for (int dst=0; dst < n; ++dst) {
		if(a[cur][dst] == 1 && T[dst] == -1) {
			dfs(dst);
		}
	}
	F[cur] = Time;
	Time += 1;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		T[i] = -1;
		for (int j=0; j<q; ++j) {
			cin >> r;
			a[p-1][r-1] = 1;
		}
	}
	dfs(0);
	for (int i=0; i<n-1; ++i) {
		cout << i+1 << " " << T[i]+1 << " " << F[i]+1 << endl;
	}
	cout << n << " " << T[n-1]+1 << " " << F[n-1]+1 << endl;
}