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 <bits/stdc++.h>

using namespace std;
typedef long long int ll;
vector<vector<int>>v;
vector<int>atime,btime;

int n;
int nowtime = 1;

void func(int i)
{
    if(atime[i] == 0) 
    {
        atime[i] = nowtime;
        nowtime++;
    }
    else return;
    for(auto x:v[i]) func(x);
    btime[i] = nowtime;
    nowtime++;
}

int main()
{
    int n;
    cin >> n;
    v.resize(n);
    atime.resize(n);
    btime.resize(n);
    for(int i = 0; i < n; i++)
    {
        atime[i]=0;
        btime[i]=0;
        int u,k;
        cin >> u >> k;
        for(int j = 0; j < k; j++)
        {
            int p;
            cin >> p;
            p--;
            v[i].push_back(p);
        }
    }
    for(int i = 0; i < n; i++) func(i);
    for(int i = 0; i < n; i++) cout << i+1 << " " << atime[i] << " " << btime[i] << endl; 
    
}

C++: //ALDS1_11_B:Depth First Search
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

vector<int> v[101];
int d[101];
int f[101];
bool already[101];

int t = 1;

void dfs(int now){
    d[now] = t;
    t++;
    already[now] = 1;
    for(int i=0; i<v[now].size(); i++){
        if(!already[v[now][i]]) dfs(v[now][i]);
    }
    f[now] = t;
    t++;
}

int main(){
    int n;
    cin >> n;
    
    for(int i=0; i<n; i++){
        int u,k;
        cin >> u >> k;
        for(int j=0; j<k; j++){
            int tmp;
            cin >> tmp;
            v[u].push_back(tmp);
        }
        already[u] = false;
        sort(v[u].begin(), v[u].end());
    }

    for(int i=1; i<=n; i++){
        if(!already[i]) dfs(i);
    }

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define N 2000

using namespace std;
vector<vector<int> > pa;
vector<vector<int> > ch;
int first[N] = {0};
int second[N] = {0};
int timestamp = 0;
void dfs(int x) {
    if (ch[x].empty()) {
        return;
    } else {
        for (int i = 0; i < ch[x].size(); i++) {
            if (first[ch[x][i]] == 0 && second[ch[x][i]] == 0) {
                timestamp++;
                first[ch[x][i]] = timestamp;
                dfs(ch[x][i]);
                timestamp++;
                second[ch[x][i]] = timestamp;
            }
        }
        return;
    }
}
int main() {
    int n;
    cin >> n;
    int temp = n;
    pa.clear(); pa.resize(N + 5);
    ch.clear(); ch.resize(N + 5);
    while (temp--) {
        int u, k, v;
        cin >> u >> k;
        for (int i = 0; i < k; i++) {
            cin >> v;
            pa[v].push_back(u);
            ch[u].push_back(v);
        }
    }
    int an = 0;
    for (int i = 1; i <= n; i++) {
        if (pa[i].empty()) {
            an = i;
        } else {
            sort(pa[i].begin(), pa[i].end(), less<int>());
        }
        if (ch[i].empty()) {
            ;
        } else {
            sort(ch[i].begin(), ch[i].end());
        }
    }
    timestamp++;
    first[an] = timestamp;
    dfs(an);
    timestamp++;
    second[an] = timestamp;
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << first[i] << ' ' << second[i] << '\n';
    }
}

// int main(){
//     for (int i = 1 ; i <= n ; i++)
//         if (discovered[i] == -1)
//             dfs(i);
// }
// 
// void dfs(int cur){
//     discovered[cur] = stamp++;
//     for (int i = 0 ; i < pa[cur].size() ; i++)
//         if (discovered[cur] == -1)
//             dfs(pa[cur][i]);
//     visited[cur] = stamp++;
// }

C++: #include<iostream>
#include<stack> 
const int MAXN = 105;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int a[MAXN][MAXN];
int color[MAXN];
int d[MAXN];
int f[MAXN];
int nt[MAXN];
int n, tt = 0;
using namespace std;

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

void dfs(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_init()
{
	int u;
	for(u = 0; u < n; u++)
	{
		color[u] = WHITE;
		nt[u] = 0;
	}
	tt = 0;
	for(u = 0; u < n; u++)
	{
		if(color[u] == WHITE)
			dfs(u);
	}
	
	for(u = 0; u < n; u++)
	{
		cout << u+1 << " " << d[u] << " " << f[u] << endl;	
	}	
} 

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