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

int now_time = -1, time_stamp_d[101]{}, time_stamp_f[101]{};
int vertices_num;
std::vector<int> dest[101];
void search(int);

int main()
{
	int vertex_tmp, dest_num, dest_tmp;

	std::cin >> vertices_num;
	for (int i = 1; i <= vertices_num; ++i)
	{
		std::cin >> vertex_tmp >> dest_num;
		for (int j = 0; j < dest_num; ++j)
		{
			std::cin >> dest_tmp;
			dest[vertex_tmp].push_back(dest_tmp);
		}
		dest[0].push_back(i);
	}
	
	search(0);

	for (int i = 1; i <= vertices_num; ++i)
	{
		std::cout << i << " " << time_stamp_d[i] << " " << time_stamp_f[i] << std::endl;
	}

	return 0;
}

void search(int now_place)
{
	time_stamp_d[now_place] = ++now_time;
	for (auto e : dest[now_place])
	{
		if (time_stamp_d[e]) continue;
		search(e);
	}
	time_stamp_f[now_place] = ++now_time;
	return;
}

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

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

int n, M[N][N];
int color[N], d[N], f[N], tt;

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() {
  int u;
  for ( u = 0; u < n; u++ ) color[u] = WHITE;
  tt = 0;

  for ( u = 0; u < n; u++ ) {
    if ( color[u] == WHITE ) dfs_visit(u);
  }
  for ( u = 0; u < n; u++ ) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  scanf("%d", &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++ ) {
    int a, b;
    cin >> a >> b;
    a--;
    for ( int j = 0; j < b; j++ ) {
      int c;
      cin >> c;
      c--;
      M[a][c] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int n;
int d[101], v[101];
int graph[101][101] = {};

int solve(int k, int cnt)
{
	d[k] = cnt;
	int nowcnt = cnt;
	for(int i = 0; i < n; i++){
		if(d[i] < 0 && graph[k][i] > 0) nowcnt = solve(i, nowcnt + 1);
	}
	return v[k] = nowcnt + 1;
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		d[i] = -1;
		v[i] = -1;
		int u, k;
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			v--;
			graph[u][v] = 1;
		}
	}
	int nowcnt = 1;
	for(int i = 0; i < n; i++){
		if(d[i] < 0) nowcnt = solve(i, nowcnt) + 1;
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << d[i] << " " << v[i] << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int curTime = 1;
void dfs(int cur, const vector<vector<bool> >& a, vector<int>& d, vector<int>& f, vector<bool>& visited){
  visited[cur] = true;
  d[cur] = curTime;
  curTime++;
  // cerr << "visiting [" << cur << "], time = " << curTime << endl;

  for(int dst = 1; dst <= a.size(); dst++){
    if(a[cur][dst] && !visited[dst]) {// cur????????¶??????????????????????????????
      dfs(dst, a, d, f, visited);
    }
  }
  f[cur] = curTime;
  curTime++;
  return;
}

int main(){
  int n;
  cin >> n;
  vector<vector<bool> > a(n+1, vector<bool>(n+1, false));
  for(int i = 1; i <= n; i++){
    int u;
    cin >> u;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      a[i][v] = true;
    }
  }

  vector<bool> visited(n+1, false);
  vector<int> d(n+1), f(n+1);

  for(int i = 1; i <= n; i++){
    if(!visited[i]){
      dfs(i, a, d, f, visited);
    }
  }

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

C++: #include<iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

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(){
    int u;
    for(u=0; u<n; u++){
        color[u]=WHITE;
    }
    tt=0;
    for(u=0; u<n; u++){
        if(color[u]=WHITE){dfs_visit(u);}
    }
    for(u=0; u<n; u++){
        printf("%d %d %d",u+1,d[u],f[u]);
    }
}

int main(){
    int i,j,k,u,v,n;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j]=0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    dfs();
    return 0;
}

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

const int MAX = 100;
int n;
int G[MAX + 1][MAX + 1];
int bt[MAX + 1], et[MAX + 1];
int states[MAX + 1];
int t = 0;

void dfs(int id) {
  if (states[id] == 1) return;
  states[id] = 1;
  bt[id] = ++t;
  for (int i = 0; i < n; i++) {
    if (G[id][i] == 1 && states[i] == 0) {
      dfs(i);
    }
  }
  et[id] = ++t;
}

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

  cin >> n;

  int u, v, k;

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

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

  for (int i = 0; i < n; i++) {
    dfs(i);
  }

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

  return 0;
}

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

using namespace std;

typedef vector<int> vec;
typedef vector<vec> Graph;

Graph G(110);
int T,In[110],Out[110];
bool used[110];

void dfs(int x)
{
	used[x]=true;
	In[x]=++T;
	for(int i=0;i<G[x].size();i++)
		if(!used[G[x][i]])
			dfs(G[x][i]);
	Out[x]=++T;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v;
			scanf("%d",&v);
			G[u].push_back(v);
		}
	}
	memset(used,false,sizeof(used));
	T=0;
	dfs(1);
	for(int i=1;i<=n;i++)
		printf("%d %d %d\n",i,In[i],Out[i]);
	return 0;
}