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 <iostream>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
    }
    for (int i = 0; i < n; i++) {
        if (adj_matrix[v][i] != 0) {
            dfs(i, n);
        }
    }
    if (f[v] == 0) {
        f[v] = t;
        t++;
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
    }

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

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

    dfs(0, n);

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i,n) for(int i = 0; i < n; i++)
int n;
int g[101][103];
void dfs(int v);
using namespace std;
int t = 0;
int main(){
  int u,k,v;
  cin >> n;
  lp(n) {
    cin >> u >> k;
    lpp(j,k) {
      cin >> v;
      g[u][v] = 1;
    }
  }
  int y = 1;
  while(y != 0){
    dfs(y);
    y = 0;
    lp(n) {
      if(g[0][i+1] == 0) {
	y = i+1;
	break;
      }
    }
  }
  lp(n) cout << i+1 << " " << g[i+1][101] << " " << g[i+1][102] << endl;
  return 0;
}
void dfs(int v) {
  g[0][v] = 1;
  g[v][101] = ++t;
  lp(n){
    if(g[v][i+1] == 1 && g[0][i+1] == 0){
      dfs(i+1);
    }
  }
  g[v][102] = ++t;
  /*
  int v;
  int t = 1;
  vector<int> st;
  int *visited = g[0];
  v = 1;
  visited[v] = 1;
  st.push_back(v);
  g[v][101] = t;
  while(!st.empty()) {
    lp(st.size()) cout << st[i]<<" ";cout<<endl;
    v = st.front();
    st.pop_back();
    lp(100) {
      if(g[v][i+1] == 1) {
	if(visited[i+1] == 0) {
	  visited[i+1] = 1;
	  st.push_back(i+1);
	  g[i+1][101] = ++t;
	}
      }
    }
    }*/
}

C++: #include<stdio.h>
struct
{
    int Top=0;
    int s[20000];
    bool Empty()
    {
        return Top==0;
    }
    void push(int x)
    {
        s[++Top]=x;
    }
    void pop()
    {
        Top--;
    }
    int top()
    {
        return s[Top];
    }
}S;
const int N=100;
const int bai=0;
const int hui=1;
const int hei=2;
int n,tu[N][N];
int fx[N],js[N],sum,nt[N],jilu[N];
int next(int u)
{
    for (int v=nt[u];v<n;v++)
    {
        nt[u]=v+1;
        if(tu[u][v]) return v;
    }
    return -1;
}
void DFS_visit(int r)
{

    S.push(r);
    jilu[r]=hui;
    fx[r]=++sum;
    while(!S.Empty())
    {
        int u=S.top();
        int v=next(u);
        if(v!=-1)
        {
            if(jilu[v]==bai)
            {
                jilu[v]=hui;
                fx[v]=++sum;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            jilu[u]=hei;
            js[u]=++sum;    
        }
    }
}
void DFS()
{
    sum=0;
    for (int u=0;u<n;u++)
    {
        if(jilu[u]==bai)
            DFS_visit(u);
    }
    for (int i=0;i<n;i++)
    {
        printf("%d %d %d\n",i+1,fx[i],js[i]);
    }
}
int main()
{
    int u,k,v;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        u--;
        for(int j=0;j<k;j++)
        {
            scanf("%d",&v);
            v--;
            tu[u][v]=1;
        }
    }
    DFS();
    return 0;
}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
*/

int table[101][101], time_table[101][2];
int common_time = 1, n;

void dfs(int node){
    if(time_table[node][0] == 0) time_table[node][0] = common_time++;
    else return;
    for(int i = 1; i <= n; i++){
        if(table[node][i] == 1) dfs(i);
    }
    time_table[node][1] = common_time++;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int id, k, v;
    rep(i,n+1){
        rep(j,n+1) table[i][j] = 0;
        time_table[i][0] = 0;
        time_table[i][1] = 0;
    }
    rep(i,n){
        cin >> id >> k;
        rep(j,k){
            cin >> v;
            table[id][v] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        dfs(i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << time_table[i][0] << " " << time_table[i][1] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int n,g[100][100],c[100],f[100],e[100],t=1;
void dfs(int now){
  c[now]=1;
  f[now]=t;
  t++;
  for(int i=0;i<n;i++) if(g[now][i]&&c[i]!=1){
      dfs(i);
      t++;
    }
  e[now]=t;
}
int main(){
 
  int a,b,tmp;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=0;j<b;j++){
      cin>>tmp;
      g[a-1][tmp-1]=1;
    }
  }
  for(int i=0;i<n;i++) if(c[i]!=1){
      dfs(i);
      t++;
    }
 
  for(int i=0;i<n;i++) cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
 
  return 0;
 
}

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 ALL(obj) (obj).begin(),(obj).end()
using namespace std;

const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<bool> seen;
vector<int> start_time;vector<int> finish_time;
vector<vector<int> > g;
void dfs(int ind,int& cnt){
    start_time[ind]=++cnt;
    seen[ind]=true;
    for(int nextind : g[ind]){
        if(seen[nextind])continue;
        dfs(nextind,cnt);
    }
    finish_time[ind]=++cnt;
}
signed main () {
    int n;scanf("%d",&n);
    g.resize(n);
    REP(i,n){
        int ind,tmp;scanf("%d %d",&ind,&tmp);
        REP(j,tmp){
            int a;scanf("%d",&a);
            g[i].push_back(a-1);
        }
    }
    seen.assign(n,false);start_time.resize(n);finish_time.resize(n);
    int cnt =0;
    REP(i,n){
        if(seen[i])continue;
        dfs(i,cnt);
    }
    REP(i,n){
        printf("%d %d %d\n",i+1,start_time[i],finish_time[i]);
    }
    return 0;
}