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 <iostream>
#include <vector>

using namespace std;

void dfs(int n, vector<vector<int> > &G, int s, int *d, int *f, int &t) {
    d[s] = t++;
    for (int i = 0; i < G[s].size(); i++) {
        int v = G[s][i];
        
        if (d[v] != -1)
            continue;

        dfs(n, G, v, d, f, t);
    }
    f[s] = t++;
}

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

    int *f = new int[n], *d = new int[n];
    for (int i = 0; i < n; i++)
        f[i] = d[i] = -1;

    int t = 1;
    for (int i = 0; i < n; i++) {
        if (d[i] == -1)
            dfs(n, G, i, d, f, t);
    }

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if(matrix[cur-1][l[cur][i]-1]==1)
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
}
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;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    dfs(1);
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

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

const static int MAX = 100;
int G[MAX][MAX];
int nt[MAX];
int n;

int nextNode(int x){
    for(int i = nt[x]; i < n; i++){
	if(G[x][i] == 1){
	    nt[x] = i + 1;
	    return i;
	}
    }
    return -1;
}

int main(void){
    std::stack<int> st;
    int color[MAX], a[MAX], b[MAX];
    int u, k, v, time;

    time = 0;
    std::cin >> n;

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

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

    for(int i = 0; i < n; i++){
	if(color[i] == 0){
	    st.push(i);
	    color[i] = 1;
	    a[i] = ++time;
	}
	while(!st.empty()){
	    int cur = st.top();
	    int next = nextNode(cur);
	    if(color[next] == 0 && next != -1){
	        st.push(next);
	        color[next] = 1;
	        a[next] = ++time;
	    }
	    if(next == -1){
		st.pop();
		b[cur] = ++time;
	    }
	}
    }

    for(int i = 0; i < n; i++){
        std::cout << i+1 << " " << a[i] << " " << b[i] << std::endl;
    }


    return 0;

}

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

int DFS(bool path[110][110],int begin[],int end[],int v,int n,int t){
    t++;
    begin[v]=t;
    for(int i=0;i<n;i++){
        if(path[v][i]&&begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    t++;
    end[v]=t;
    return t;
}

int main(void){
    int n,u,k,i,j,x,t;
    bool path[110][110];
    int begin[110],end[110];
    memset(path,0,sizeof(path));
    memset(begin,0,sizeof(begin));
    cin>>n;
    for(i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(j=0;j<k;j++){
            cin>>x;
            x--;
            path[u][x]=true;
        }
    }
    
    t=0;
    for(i=0;i<n;i++){
        if(begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    
    for(i=0;i<n;i++){
        cout<<i+1<<" "<<begin[i]<<" "<<end[i]<<endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
enum Color { WHITE = 0, GRAY, BLACK};
int n, tt{0};
vv(int, M, MAX, MAX, 0);
vi color(MAX, 0), d(MAX, 0), f(MAX, 0), nt(MAX, 0);
inline int next(int u) {
	rep(v, nt[u], n) {
		nt[u] = v + 1;
		if(M[u][v]) return v;
	}
	return -1;
}
inline void dfs_visit(int r) {
	deque<int> S;
	S.eb(r);
	color[r] = GRAY;
	d[r] = ++tt;
	int u, v;
	while(!S.empty()) {
		u = S.back();
		v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.eb(v);
			}
		} else {
			S.pop_back();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}
inline void dfs() {
	tt = 0;
	rep(u, 0, n) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v;
	rep(i, 0, n) {
		cin >> u >> k;
		--u;
		rep(j, 0, k) {
			cin >> v;
			M[u][--v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <stdio.h>

const int WHITE = -1;
const int GRAY = -2;
const int BLACK = -3;

int g[101][101], time1[101], time2[101], visit[101];
int n, u, k, m;
int t;

void dfs(int root)
{
	time1[root] = ++t;
 visit[root] = GRAY;
	for (int i = 1; i <= n; i++)
	{
		if (g[root][i] != -1 && visit[i] == WHITE)
		{
			visit[i] = GRAY;
			dfs(i);
		}
	}
	visit[root] = BLACK;
	time2[root] = ++t;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		visit[i] = WHITE;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			g[i][j] = -1;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++)
		{
			scanf("%d", &m);
			g[u][m] = 1;
		}
	}
	dfs(1);
	for (int i = 1; i <= n; i++)
	{
		printf("%d %d %d\n", i, time1[i], time2[i]);
	}

	return 0;
}