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)
	dfs(&g, &d, &f, 1, 1)

	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++: #define _CRT_SECURE_NO_WARNINGS
#define MAX 2000000000
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std ;

int d[102] = { 0 }, f[102] = { 0 };
int M[102][102];

int main() {
	stack<int> stk;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		int k,l,m;
		cin >> m;
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> l;
			M[m][l] = 1;
		}
	}
    
	stk.push(1);

    int i = 1,time=1;
    d[1]=1;
	while (!stk.empty()) {
		if (M[stk.top()][i] == 1 && d[i] == 0) {
			stk.push(i);
			time++;
			d[i] = time;
			i = 1;
		}
		else {
			i++;
			if (i > n) {
			    time++;
				f[stk.top()] = time;
				stk.pop();
				i=1;
			}
		}
	}

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

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int time = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	::time++;
	a[t].t = ::time;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	::time++;
	a[t].e = ::time;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int n, t = 0;
vector<vector<int> > G(110);
pair<int, int> toki[110];
bool vis[110];

void dfs(int v)
{
    if(vis[v]) return;
    t++;
    toki[v].first = t;
    vis[v] = true;
    rep(i, G[v].size())
    {
        if(vis[G[v][i]]) continue;
        dfs(G[v][i]);
    }
    t++;
    toki[v].second = t;
    return;
}

int main(void)
{
    cin >> n;
    rep(i, n) vis[i] = false;
    rep(i, n)
    {
        int t, k;
        cin >> t >> k;
        t--;
        rep(j, k)
        {
            int v;
            cin >> v;
            v--;
            G[t].push_back(v);
        }
    }
    rep(i, n)
    {
        dfs(i);
    } 
    rep(i, n)
    {
        cout << i+1 << " " << toki[i].first << " " << toki[i].second << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int d[101],f[101],G[101][101];
stack<int>s;
int n,t;
void dfs(int u)
{
    s.push(u);
    d[u]=t++;
    int i;
    while(!s.empty()){
        u=s.top();
        for(i=1;i<=n;i++)
        {
            if(G[u][i]==1 && d[i]==0)
            {
                s.push(i);
                d[i]=t++;
                //u=i;
                break;
            }
        }
        if(i>n)
        {
            f[s.top()]=t++;
            s.pop();
        }
    }
}
int main()
{
    int k,u,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=0;
        for(int j=1;j<=n;j++)
            G[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            G[u][v]=1;
        }
    }
    t=1;
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
            dfs(i);
    }
    for(int i=1;i<=n;i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Graph g(n);
    REP(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            add_edge(g, u, v, 1, false, 1);
        }
    }

    Array d(n, 0);
    Array f(n, 0);
    int id = 1;
    auto dfs = [&](auto &&self, int v) -> void {
        d[v] = id;
        id++;
        for(auto e : g[v]) {
            if(d[e.to])
                continue;
            self(self, e.to);
        }
        f[v] = id;
        id++;
    };
    REP(i, n) {
        if(d[i])
            continue;
        dfs(dfs, i);
    }
    REP(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << en;
    }
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}

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

int N;
const int maxn = 105;
const int WHITE = 0;
const int BLACK = 2;
int G[maxn][maxn];
vector<int> color;
vector<int> startTime;
vector<int> endTime;
vector<int> nt;

int getNext(int u){
    int res = -1;
    for(int i = nt[u];i<N;i++){
        if(G[u][i] && color[i]==WHITE){
            res = i;
            nt[u] = i;
            break;
        }
    }
    return res;
}

void DFS(int u,int &time){
    if(color[u]!=WHITE) return;
    stack<int> nodeStack;
    nodeStack.push(u);
    startTime[u] = time++;
    while(!nodeStack.empty()){
        int u = nodeStack.top();
        //if(color[u]!=WHITE) continue;
        color[u] = BLACK;

        int v = getNext(u);
        if(v!=-1){
            startTime[v] = time++;
            nodeStack.push(v);
            continue;
        }
        else{
            endTime[u] = time++;
            nodeStack.pop();
        }
    }
}

int main(){
    //freopen("data.txt","r",stdin);
    memset(G,0,sizeof(G));
    cin >> N;
    color.resize(N,WHITE);
    startTime.resize(N,0);
    endTime.resize(N,0);
    nt.resize(N,0);
    int u,k;
    for(int i = 0;i<N;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(int j = 0;j<k;j++){
            int v;
            scanf("%d",&v);
            v--;
            G[u][v] = 1;
        }
    }
    int time = 1;
    for(int i = 0;i<N;i++) if(color[i]==WHITE) DFS(i,time);
    for(int u = 0;u<N;u++){
        printf("%d %d %d\n",u+1,startTime[u],endTime[u]);
    }
    return 0;
}