Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

vector<int> g[105];
int d[105], f[105], visited[105];
int t = 1;

void dfs(int x){
    d[x] = t++;
    visited[x] = 1;
    for(int y: g[x]){
        if(visited[y] == 1) continue;
        dfs(y);
    }
    f[x] = t++;
}

int main(){
    int n;
    cin >> n;
    rep(i,n+1){
        d[i] = 0;
        f[i] = 0;
        visited[i] = 0;
    }
    rep(i,n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for(int i = 1; i <= n; i++){
        if (visited[i] == 0){
            dfs(i);
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    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;
		}
	}
	solve(0, 1);
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << d[i] << " " << v[i] << endl;
	}
}

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

using namespace std;

long long inf=1000000007;
vector<bool> seen(10000,false);

void dfs(long long &cnt,long long now,vector<long long> &d,vector<long long> &f,vector<vector<long long>> kankei){
	seen.at(now)=true;
	cnt++;
	d.at(now)=cnt;

	for(auto a:kankei.at(now)){
		if(seen.at(a)) continue;

		dfs(cnt,a,d,f,kankei);
	}

	cnt++;
	f.at(now)=cnt;

	return;
}

int main(){
	long long n;
	cin>>n;
	vector<vector<long long>> kankei(n+1);

	for(long long i=1;i<=n;i++){
		long long k,u;
		cin>>k>>u;
		vector<long long> vec(u);
		for(long long j=0;j<u;j++){
			cin>>vec.at(j);
		}
		sort(vec.begin(),vec.end());

		kankei.at(k)=vec;
	}

	vector<long long> d(n+1,0);
	vector<long long> f(n+1,0);
	long long cnt=0;

	for(long long i=1;i<=n;i++){
		if(seen.at(i)) continue;

		dfs(cnt,i,d,f,kankei);
	}

	for(long long i=1;i<=n;i++){
		cout<<i<<" "<<d.at(i)<<" "<<f.at(i)<<endl;
	}

	return 0;
}

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

#define MAX_N 101

int counter;
int d[MAX_N];
int f[MAX_N];

void DFS(list<int>* G, int n){
	counter++;
	d[n] = counter;
	list<int>::iterator it;
	for(it=G[n].begin(); it!=G[n].end(); it++){
		if(d[*it-1]==0) DFS(G, *it-1);
	}
	counter++;
	f[n] = counter;
}

int main()
{
	counter = 0;
	for(int i=0; i<MAX_N; i++) d[i]=f[i]=0;
	int n;cin>>n;
	list<int> G[n];
	
	// input Graph data
	for(int i=0; i<n; i++){
		int u, k, v;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			cin >> v;
			G[u-1].push_back(v);
		}
	}
	// DFS
	for(int i=0; i<n; i++){
		if(d[i]==0){
			DFS(G, i);
		}
	}
	// Output Result
	for(int i=0; i<n; i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

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

int main(){
 int n,k,v,u;
  cin>>n;

  int V[100][100]; //隣接リスト
  int cnt[100];　//各点においてどこまでみたかの把握
  int d[100];
  int f[100];
  int time=1;
  int l=0;
  int come[100]; //その点はどこからきたかの把握

  //初期化
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      V[i][j]=0;
      cnt[j]=0;
      d[j]=0;
      f[j]=0;
      come[j]=0;
    }
  }
  //グラフ情報の読み込み
 int  m=0;
  for(int i=0;i<n;i++){
    cin>>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      V[u-1][m]=v;
      m++;
    }
    m=0;
  }


  //スタートは0
 d[0]=1;
 time++;
  while(1){

    if(time==2*n+1) break;
    //先がありかつそこは探索終了していない
    if(V[l][cnt[l]]!=0 && f[V[l][cnt[l]]-1]==0){ 
     
      if(d[V[l][cnt[l]]-1]==0) d[V[l][cnt[l]]-1]=time;

   come[V[l][cnt[l]]-1]=l;
      cnt[l]++;
      l=V[l][cnt[l]-1]-1; 

      time++;
      //先がないまたはさきが探索終了している
    }else{

      if(d[l]==0) d[l]=time;
       f[l]=time;
      l=come[l];
      time++;

    }

  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    cout<<V[i][j]<<" ";
    if(j==n-1) cout<<endl;
  }
  }
  */
  //出力
  for(int i=0;i<n;i++){

    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }


  return 0;
}

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

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

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++) ;
    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;
}