Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

using Graph = vector<vector<int>>;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variety
int N;
int d[110];
int f[110];
int ans;
// function
void solve();
void dfs(const Graph &G, int v);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

void solve(){
    cin >> N;
    Graph G(N);
    rep(i, N){
        int hoge; cin >> hoge;
        int k; cin >> k;
        rep(j, k){
            int tmp;
            cin >> tmp;
            tmp--;
            G[i].push_back(tmp);
        }
    }
    rep(i, N) d[i] = -1;
    rep(i, N) f[i] = -1;
    ans = 0;
    for (int i = 0; i < N; i++){
        if (d[i] != -1) continue;
        ans++;
        dfs(G, i);
    }
    rep(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return ;    
}

void dfs(const Graph &G, int v){
    d[v] = ans;
    for(auto next_v : G[v]){
        if (d[next_v] != -1) continue;
        ans++;
        dfs(G, next_v);
    }
    ans++;
    f[v] = ans;
}

C++: #include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

vb seen;
vi k;
vi d;
vi f;

int dfs(const Graph &G, int v, int t) {
    seen[v] = true;
    d[v] = t;
    REP(i, k[v]) {
        int next_v = G[v][i];
        if (seen[next_v]) continue;
        t = dfs(G, next_v, t+1);
    }
    t += 1;
    f[v] = t;
    return t;
}

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

    int n; cin >> n;
    Graph G(n);
    REP(i, n) {
        int u; cin >> u;
        int tmp; cin >> tmp;
        k.push_back(tmp);
        REP(j, tmp) {
            int v; cin >> v;
            G[i].push_back(v-1);
        }
    }

    seen.assign(n, false);
    d.assign(n, 0);
    f.assign(n, 0);

    int t = 0;
    REP(i, n) {
        if (seen[i]) continue;
        t = dfs(G, i, t+1);
    }

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

C++: #include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
int M[N][N],n;
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color [u] = GRAY ;
  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(i = 0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v] =1;
      }
  }
  dfs();
  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,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u)
{
    for (int v = nt[u]; v < n; v++)
    {
        nt[u]=v+1;
        if(M[u][v])return v;
    }
    
    return -1;
}

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=next(u);
        if(v!=-1)
        {
            if(color[v]==WHITE)//未訪問なら訪問
            {
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();//もどる
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

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

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

    return 0;
}

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

using namespace std;

int G[100][100];
int In[100];
int Out[100];
void init() {
	for (int i = 0; i < 100; i++) {
		for(int j = 0; j < 100; j++)
			G[i][j] = 0;
		In[i] = -1;
		Out[i] = -1;
	}	
}

void dfs(int src);

int main() {
	init();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v_j;
			cin >> v_j;
			G[u - 1][v_j - 1] = 1;
		}
	}
	dfs(0);
	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << In[i] << " " << Out[i] << endl;
}

int t = 1;

void dfs(int cur) {
	In[cur] = t;
	t++;
	for (int dst = 0; dst < 100; dst++)
		if (G[cur][dst] == 1 && In[dst] == -1)
			dfs(dst);
	Out[cur] = t;
	t++;
}