Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int d[101] = {};
int f[101] = {};
int t = 0;
vector<int> G[101];

void dfs(int x){
    t++;
    d[x] = t;
    for(auto y:G[x]){
        if(d[y]==0)dfs(y);
    }
    t++;
    f[x] = t;
}

/*----------------------------------------------------------------*/
signed main(){

    int n;
    cin >> n;
    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(i,k){
            int v;
            cin >> v;
            G[u-1].pb(v-1);
        }
    }
    rep(i,n)if(d[i]==0)dfs(i);
    rep(i,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://arc054.contest.atcoder.jp/tasks/arc054_b

C++: #include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int SIZE = 101;
int d[SIZE], f[SIZE], a[SIZE][SIZE];
int t = 1;

void dfs(int u, int n) {
  d[u] = t;
  t++;
  rep(i, n) {
    if (a[u][i] && d[i] == 0 && f[i] == 0) dfs(i, n);
  }
  f[u] = t;
  t++;
}

int main() {
  int n;
  std::cin >> n;

  rep(i, n) rep(j, n) a[i][j] = 0;

  rep(i, n) {
    int u, k, v;
    std::cin >> u >> k;
    rep(j, k) {
      std::cin >> v;
      a[u - 1][v - 1] = 1;
    }
  }

  rep(i, n) if (d[i] == 0 && f[i] == 0) dfs(i, n);

  rep(i, n) { std::cout << i + 1 << ' ' << d[i] << ' ' << f[i] << '\n'; }

  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

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 u = S.top();
		int v = 0;
		while(M[u][v] == 0 && v < n) {
			v++;
		} 
		if(v != n) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;
		
	for(int u = 0; u < n; u++) {
		if(color[u]) dfs_visit(u);
	}

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

int main() {
	int k , u, v;
	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 i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

C++: #include<iostream>
const int MAXN = 105;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int a[MAXN][MAXN];
int color[MAXN];
int d[MAXN];
int f[MAXN];
int n, tt = 0;
using namespace std;

void dfs(int u)
{
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v = 0; v < n; v++)
	{
		if(a[u][v] == 0)
			continue;
		if(color[v] == WHITE)
		{
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_init()
{
	int u;
	for(u = 0; u < n; u++)
		color[u] = WHITE;
	
	for(u = 0; u < n; u++)
	{
		if(color[u] == WHITE)
			dfs(u);
	}
	
	for(u = 0; u < n; u++)
	{
		cout << u+1 << " " << d[u] << " " << f[u] << endl;	
	}	
} 

int main ()
{
	int k, u, temp;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++)
		{
			cin >> temp;
			temp--;
			a[u][temp] = 1;
		}
	}
	dfs_init();
	return 0;
}

C++: #include<stdio.h>
#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) { //再帰によるDFS
	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() {
	int u, v, k, i, j;
	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++: /*
** dfs 遍历图
*/

# include <cstdio>
# include <cstring>
# include <stack>
using namespace std;

const int MAX = 100 + 2;

int g[MAX][MAX], d[MAX], f[MAX], c[MAX], n;

void init() {
    memset(g, 0, sizeof(g));
    memset(d, 0, sizeof(d));
    // memset(f, 0, sizeof(f));
    memset(c, 0, sizeof(c));
    scanf("%d", &n);
    int u, v, k;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &u, &k);
        while (k--) {
            scanf("%d", &v);
            g[u][v] = 1;
        }
    }
}

void dfs() {
    stack<int> s;
    s.push(1);
    int t = 1, node;
    d[1] = t;
    c[1] = 1;

    while(!s.empty()) {
        t++;
        node = s.top();
        int p = 1;
        for (; p <= n; p++) {
            if (g[node][p] != 0 && c[p] == 0) {
                s.push(p);
                d[p] = t;
                c[p] = 1;
                break;
            }
        }
        if (p > n) {
            f[node] = t;
            s.pop();
        }
    }
}

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

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}