Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <iostream>
#include <stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
int color[MAX];
int s_timer[MAX], b_timer[MAX], pass;

void dfs_search(int u) {
    int v;
    color[u] = GRAY;
    s_timer[u] = ++pass;
    for (v = 0; v < n; v++) {
        if (M[u][v] == 0) continue;
        if (color[v] == WHITE) {
            dfs_search(v);
        }
    }
    color[u] = BLACK;
    b_timer[u] = ++pass;
}

void dfs() {
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    pass = 0;
    
    for (int j = 0; j < n; j++) {
        if (color[j] == WHITE) dfs_search(j);
    }
    
    for (int t = 0; t < n; t++) {
        printf("%d %d %d\n", t+1, s_timer[t], b_timer[t]);
    }
}

int main() {
    int u, k, v;
    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++) {
        scanf("%d %d", &u, &k);
        u--;
        if (k == 0) continue;
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

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

int visit[100],end[100],a[100][100];
int t,N,u,k,col;

void rist_to_mat(int N) {
	for(int l=0; l<N; ++l) {
		cin >> u >> k;
		for (int i=0; i<k; ++i) {
			cin >> col;
			a[u-1][col-1] = 1;
		}
	}
}

void dfs(int cur,int N) {
	t += 1;
	visit[cur] = t;
	for(int dst=0; dst<N; ++dst) {
		if(a[cur][dst] == 1 && visit[dst] == 0) {
			dfs(dst,N);
		}
	}
	t += 1;
	end[cur] = t;
}

int main() {
	cin >> N;
	rist_to_mat(N);
	dfs(0,N);
	for(int i=0; i<N; ++i) {
		cout << i+1 << ' ' << visit[i] << ' ' << end[i] << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class DFS
{
public:
  int n;
  int solve();
  int dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f );
};

int DFS::dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f )
{
  if ( d[v] )
    return t;
  else
    d[v] = t++;

  for ( auto i = 1; i <= n; ++i )
    if ( adj[v][i] )
      t = dfs( i, t, adj, d, f );

  f[v] = t;

  return ++t;
}

int DFS::solve()
{
  cin >> n;

  vector<vector<int>> adj(n+1, vector<int>(n+1, 0));
  vector<int> d(n+1,0);
  vector<int> f(n+1,0);

  for ( auto i = 0; i < n; ++i )
    {
      int x, k;
      cin >> x;
      cin >> k;
      for ( auto j = 0; j < k; ++j )
        {
          int y;
          cin >> y;
          adj[x][y] = 1;
        }
    }

  dfs( 1, 1, adj, d, f );

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

int main()
{
  DFS d;

  d.solve();

  return 0;
}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int adj_matrix[N_MAX+1][N_MAX+1];

int d[N_MAX+1];
int f[N_MAX+1];

stack<int> route;

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

    int n;
    cin >> n;

    int id, k, v;
    FOR(i,0,n) {
        cin >> id;
        cin >> k;
        FOR(j,0,k) {
            cin >> v;
            adj_matrix[id][v] = 1;
        }
    }

    const int TIMELIMIT = 2 * n;

    int cur = 1;
    route.push(0);
    route.push(0);

    FOR(t,1,TIMELIMIT) {
        if (!d[cur]) {
            d[cur] = t;
            //cout << t << " " << cur << " start" << endl;
        }
        int next = 0;
        FOR(i,1,n+1) {
            if (adj_matrix[cur][i] && !d[i]) {
                next = i;
                break;
            }
        }
        if (next == 0) {
            f[cur] = t + 1;
            cur = route.top();
            route.pop();
            //cout << t << " " << cur << " back" << endl;
        } else {
            route.push(cur);
            cur = next;
            //cout << t << " " << cur << " next" << endl;
        }
    }

    FOR(i,1,n+1) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

typedef struct edge_def {
  int from;
  int to;
  int cost;

  edge_def(int _from, int _to, int _cost) {
    from = _from;
    to   = _to;
    cost = _cost;
  }
} edge;

const int V = 100;
int n, t;
vector<edge> es[V];
int d[V], f[V];

void dfs(int v) {
  int i;
  d[v] = ++t;
  for (i=0; i<(int)es[v].size(); i++) {
    int to = es[v][i].to;
    if (d[to] == -1) dfs(to);
  }
  f[v] = ++t;
}

int main() {
  int i, j;
  memset(d, 0xff, sizeof(d));
  memset(f, 0, sizeof(f));
  for (i=0; i<V; i++) es[i].clear();

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

  t = 0;
  dfs(0);

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

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count);


int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	int count=1;
	a[0]=1;
	dfs(n,0,k,v,a,b,count);

	rep(i,n){
		if(a[i]==0){
			dfs(n,i,k,v,a,b,count);
		}
	}


	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;
	}

	return 0;
}
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count){
	/*if(k[x]==0){
		count++;
		a[x]=count;
	}*/
	rep(i,k[x]){
		if(a[v[x][i]]==0){
			count++;
			a[v[x][i]]=count;
			dfs(n,v[x][i],k,v,a,b,count);
		}
		if(i==k[x]-1){
			k[x]=0;
		}
	}
	if(k[x]==0){
		count++;
		b[x]=count;
	}
	return 0;
}