Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define N_MAX 100

typedef struct _v {
    int k;
    int *v;
    int f;
    int l;
} Vertex;
Vertex Adj[N_MAX];

int t = 0;

void depth_search(int i) {
//    printf(" i %d\n", t);
    if (Adj[i].f == 0) {
        Adj[i].f = t;
//        printf("  Adj[%d] : k = %d f = %d\n", i, Adj[i].k, t);
    }
    else {
        t--;
        return;
    }

    for (int j = 0; j < Adj[i].k; j++) {
        t++;
//        printf("t:%d\n", t);
        depth_search(Adj[i].v[j]);
    }
    t++;
//    printf("t:%d\n", t);
    Adj[i].l = t;
//    printf(" Adj[%d].l = %d\n", i, Adj[i].l);
    return;
}

int main() {
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int k;
        cin >> k >> k;
        Adj[i].k = k;
        Adj[i].v = new int[k];
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            Adj[i].v[j] = v - 1;
        }
        Adj[i].f = 0;
        Adj[i].l = 0;
    }

    for (int i = 0; i < n; i++) {
        t++;
        depth_search(i);
        cout << i + 1 << " " << Adj[i].f << " " << Adj[i].l << endl;
    }

    return 0;
}

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

const int MAX = 110;
int mat[MAX][MAX];
int d[MAX], f[MAX];
int n, t;

void dfs(int i)
{
  if (d[i] != -1) return;
  d[i] = ++t;
  for (int j = 0; j < n; j++)
    if (mat[i][j])
      dfs(j);
  f[i] = ++t;
}

int main()
{
  cin >> n;
  memset(mat, 0, sizeof(mat));
  for (int i = 0; i < n; i++) {
    int u; cin >> u; u--;
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int v; cin >> v; v--;
      mat[u][v] = 1;
    }
  }
  memset(d, -1, sizeof(d));
  t = 0;
  for (int i = 0; i < n; i++)
    dfs(i);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i+1, d[i], f[i]);
  return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>

#define fp 				pop_front
#define bp 				pop_back
#define all(x) 			x.begin() , x.end()
#define mp 				make_pair
#define pb 				push_back
#define pf 				push_front
#define se 				second
#define f 				first
#define sz 				size()
#define sqr(x) 			((x) * (x))
#define cub(x) 			sqr(x) * (x)
#define ios 			std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define y1 				qazwsxedcrfvtgb
#define LOGMAX          17
#define MX              1 << 22
#define l(n)            n << 1
#define r(n)            (n << 1) + 1
#define FIND(N,pos)     ((N) & (1 << (pos)))
#define sf(h)           scanf("%d",&h)
#define sff(h,b)        scanf("%d%d",&h,&b)
#define sfff(h,b,c)     scanf("%d%d%d",&h,&b,&c)
#define TCASE(test)     for(int z = 1;z <= test;z++)
#define PRINT           printf("Case %d: ",z)
#define en              "\n"
#define lwb             lower_bound
#define upb             upper_bound
#define	pii				pair <int, int>
#define	pil				pair <int, long long>
#define	pli				pair <long long, int>
#define	pll				pair <long long, long long>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = int(1.5 * 1e7);
const int inf = 1e9 + 7;
const ll ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;

int n, x, y, k1, t, a[101][101], st[101], ft[101], was[101];
vector <int> v[101];

void dfs(int k){
	st[k] = ++t;
	was[k] = 1;
	for(int i = 0; i < v[k].sz; ++i){
		int to = v[k][i];
		if(!was[to]){
			dfs(to);
		}
	}
	ft[k] = ++t;
}

main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x >> k1;
		for(int j = 0; j < k1; ++j){
			cin >> y;
			v[x].pb(y);
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i){
		cout << i << " " << st[i] << " " << ft[i] << en;
	}
}

C++: 
#include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    for (int j = 1; j <= n; ++j) {
        if (G[i][j] != 1 || STATE[j] != NOT_VISIT) continue;
        dfs(j);
    }
    STATE[i] = FOUND;
    f[i] = ++tt;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

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

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x;
  
  memset(find_t,255,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    flag[id]=0;
    for(int l=0;l<cnt;l++){
      cin>>x;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }
  
  for(int i=1;i<=n;i++){
    if(flag[i]==0)
      DFS(i);
  }
  Print();
  
  return 0;
}

  void DFS(int p){
    if(flag[p]==0){
      find_t[p]=t++;
      flag[p]=1;
    }
    else
      return;
    
    if(lft[p]!=-1)
      DFS(lft[p]);
    if(rht[p]!=-1)
      DFS(rht[p]);

    end_t[p]=t++;
  }

  void Print(){
    for(int i=1;i<=100;i++){
      if(find_t[i]!=-1)
	printf("%d %d %d\n",i,find_t[i],end_t[i]);
    }
  }