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++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
//Graph I - Depth First Search
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

//WHITE -> ????¨?????????????
//GRAY  -> ?¨????????????????(?¨?????????????????¨???????????????????????????????????????§???????????????)
//BLACK -> ?¨??????????????????????(????¨???????????????????????????????????????????)

int n, M[N][N];
int color[N];//?????????????¨??????¶???
int d[N];//????????????
int f[N];//????????????
int tt;//time stamp

//?????°???????????±???????????¢?´¢
void dfs_visit( int u )
{
	int v;
	color[u] = GRAY;
	d[u] = ++tt;//??????????¨????
	for( v = 0; v < n; v++ ){
		if( M[u][v] == 0 ) continue;
		if( color[v] == WHITE ){
			dfs_visit( v );
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;//?¨?????????????
}
void dfs()
{
	//??¨???????????????color???WHITE????¨????
	for( int u = 0; u < n; u++ ) color[u] = WHITE;
	tt = 0;
	for( int u = 0; u < n; u++ ){
		//????¨??????? u ?????°??????????§?????????¨????????±???????????¢?´¢
		if( color[u] == WHITE ) dfs_visit( u );
	}
	for( int u = 0; u < n; u++ ){
		cout << u + 1 << " " << d[u] << " " << f[u] << endl;
	}
}
int main()
{
	int u;//???????????????
	int k;//??????u?????£??\?????????????????????
	int v;//??????u????¬???°

	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 <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>

using namespace std;
int n;
list<int> adj[101];
int d[101] = {};
int f[101] = {};

void DFS(int v)
{
    static int num = 1;
    d[v] = num++;
    while (!adj[v].empty())
    {
        if (d[adj[v].front()] == 0)
            DFS(adj[v].front());
        adj[v].pop_front();
    }
    f[v] = num++;
}

void print()
{
    for (int i = 1; i <= n; i++)
    {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main()
{
    int u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u].push_back(v);
            k--;
        }
    }

    DFS(1);

    print();

    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
int n,graph[101][101],visit[101];
int d[101],f[101],t;
const int WHITE=0;
const int GRAY=1;
void dfs(int u){
    visit[u]=GRAY;
    d[u]=++t;
    FOR(v,1,n+1){
        if(graph[u][v]==0) continue;
        if(visit[v]==WHITE) dfs(v);
    }
    f[u]=++t;
    //printf("%d %d %d\n",u,d[u],f[u]);
}
int main(){
    int u,k,v;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d%d",&u,&k);
        REP(j,k){
            scanf("%d",&v);
            graph[u][v]=1;
        }
    }
    FOR(i,1,n+1){
        if(visit[i]==WHITE) dfs(i);
    }
    FOR(i,1,n+1){
        printf("%d",i);
        printf(" %d %d\n",d[i],f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
mat g;
vll d;
vll f;
vbl vis;

lli u,k,v;

lli dfs(lli x,lli t){
    d[x] = t;
    vis[x] = true;
    for(lli i = 0;i < g[x].size();i++){
        if(!vis[g[x][i]]) t = dfs(g[x][i],t+1);
    }
    return f[x] = t + 1;
}

int main(){
    cin >> n;
    g = mat(n+1);
    d = vll(n+1);
    f = vll(n+1);
    vis = vbl(n+1);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v;
            g[u].push_back(v);
        }
    }
    dfs(1,1);
    for(lli i = 1;i <= n;i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}

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

using namespace std;


struct Edge{ //??°????????????
public:
    int src, dst;
    int weight;
    Edge(int a,int b):src(a),dst(b),weight(1){} //?????????????????????
    void setWeight(double x){
        weight = x;
    }
};
typedef vector<Edge> Edges; //???????????£??\?????????
typedef vector<Edges> Graph; //??°???????????£??\???????????¨???

typedef vector<int> Array; //??´??°?????????
typedef vector<Array> Matrix; //??´??°???????????£??\?????????

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

int n;
int tt = 0;
Matrix M(N,Array(N,0));
vector<int> d(N,0), f(N,0);
vector<int> color(N,0);


vector<int> nt(N,0);//???????????????????????????????????§?????????????¨???¶??????

int next(int u){ //???u?????\?¶??????????????????????????????????
    if (nt[u]!= n) {
        for(int i = nt[u];i<n;i++){
            if(M[u][i]){
                nt[u] = i+1;
                return i;
            }
        }
        return -1;
    } else {
        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 v = S.top();
        int w = next(v);
        if (w != -1) {
            if (color[w]==White) {
                color[w] = Gray;
                d[w] = ++tt;
                S.push(w);
            }
        } else {
            S.pop();
            color[v] = Black;
            f[v] = ++tt;
        }
    }
    
}

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


int main(){
    
    int k,v,w;
    
    cin >> n; //??°????????????????????\???
    
    for (int i=0; i<n; i++) { //??????????¬???°?????????????????\??? ???????????\??????????????£??\??????????????£??\?????????????´?
        cin >> w >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            M[w-1][v-1] = 1; //?????????
        }
    }
    
    dfs();
    
    return 0;
}