Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int n;
vector<vector<int>> g(100);

int d[100], f[100];
bool used[100] = {};
int t = 0;

void dfs(int pos){
    d[pos] = ++t;
    used[pos] = true;

    rep(i, g[pos].size()){
        if(used[g[pos][i]])continue;
        dfs(g[pos][i]);
    }

    f[pos] = ++t;
}

int main(){
    cin >> n;

    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            v--;
            g[i].push_back(v);
        }
    }

    rep(i, n){
        if(!used[i])dfs(i);
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

int main(){
  vector<int> G[100];
  stack<int> q;
  vector<int> d(100,200000000),f(100,200000000);
  int n,u,k,v,time=0;
  bool flg;
  
  cin >> n;
  //G.push_back(new vector<int>(,10));
  for (int i=0;i<n;i++){
    cin >> u>> k;
    for (int j=0;j<k;j++){
      cin >> v;
      G[u-1].push_back(v-1);
    }
  }
  for (int vi=0;vi<n;vi++){
    if (d[vi]<=time)continue;
    q.push(vi);
    d[vi]=++time;
    while (!q.empty()){
      u=q.top();
      for (int i=0;i<G[u].size();i++){
	v=G[u][i];
	if (d[v]>time){
	  q.push(v);
	  d[v]=++time;
	  flg=true;
	  break;
	}
      }
      if (!flg){
	q.pop();
	f[u]=++time;
      }else{
	flg=false;
      }
    }
    
  }
  for (int i=0;i<n;i++)
    cout << i+1 <<" "<< d[i]<<" "<<f[i]<<endl;
  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int G[101][101];
bool used[101];
int f[101],s[101];
int cnt=0;
void dfs(int now){
	cnt++;
	s[now]=cnt;
	used[now]=1;
	for(int i=1;i<=100;i++){
	if(G[now][i]&&used[i]==0)dfs(i);
	}
	cnt++;
	f[now]=cnt;
}

int main(){
int n;
cin>>n;
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][v]=1;
}
}
dfs(1);
while(true){
int f=1,next=0;

	for(int j=1;j<=n;j++){
		if(used[j]==0){
		f=0,next=j;
		break;
		}
	}

if(f)break;
else dfs(next);
}
for(int i=1;i<=n;i++){
	printf("%d %d %d\n",i,s[i],f[i]);
}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	cin>>n;
	vector<vector<int> > A(n);//????????????????????????-1?????\???????????????
	//??\???
	REP(i,n){
		int u,k;
		cin>>u>>k;
		A[i]=vector<int>(k,0);
		REP(j,k){
			int l;
			cin>>l;
			A[i][j] = l-1;
		}
	}
	//??¢?´¢
	stack<int> s;//??????????????????????????\???
	vector<int> dis(n,0);//??????????????????????????????
	vector<int> fin(n,0);//???????????????????????????
	int time=0;
	while(find(dis.begin(),dis.end(), 0) != dis.end()){
		int saisyo = find(dis.begin(),dis.end(), 0) -  dis.begin();
		//cout<<saisyo<<endl;
		s.push(saisyo);//?????????0???????????????
		while(!s.empty()){
		//REP(ss,3){
			int k = s.top();//??????????????????????????????
			if(dis[k]==0){
				time++;
				dis[k]=time;
				//cout<<"dis "<<k<<" / time "<<time<<endl;
			}
			bool isfinish=true;
			for(int i: A[k]){
				//cout<<"?????????"<<i<<endl;
				if(fin[i]==0 && i!=k){
					s.push(i);
					isfinish=false;
					break;
				}
			}
			if(isfinish){
				time++;
				fin[k]=time;
				s.pop();
				//cout<<"fin "<<k<<" / time "<<time<<endl;
			}
		}
	}
	REP(i,n){
		cout<<i+1<<" "<<dis[i]<<" "<<fin[i]<<endl;
	}
	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 <vector>
using namespace  std;

struct StSeq
{
  int m_nBgn;
  int m_nEnd;

  StSeq() : m_nBgn(0), m_nEnd(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StSeq>& rvoDFSrch)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StSeq oSeq;
  rvoDFSrch.resize(nxSiz + 1, oSeq);
}

void fnDepthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, vector<StSeq>& rvoDFSrch, int nx)
{
  static int stnCnt = 0;

  if (rvoDFSrch[nx].m_nBgn)  return;
  rvoDFSrch[nx].m_nBgn = ++stnCnt;

  for (int ny = 1; ny < cnrvvnAdjcy.size(); ++ny)
    if (cnrvvnAdjcy[nx][ny] == 1  &&
        nx != ny                )
      fnDepthFirstSearch(cnrvvnAdjcy, rvoDFSrch, ny);

  rvoDFSrch[nx].m_nEnd = ++stnCnt;
}

void fnResult(const vector<StSeq>& cnrvoDFSrch)
{
  for (int i = 1; i < cnrvoDFSrch.size(); ++i)
    cout << i <<  " " << cnrvoDFSrch[i].m_nBgn << " " << cnrvoDFSrch[i].m_nEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  vector<StSeq> voDFSrch;

  fnInput(vvnAdjcy, voDFSrch);
  for (int nx = 1; nx < voDFSrch.size(); ++nx)
    fnDepthFirstSearch(vvnAdjcy, voDFSrch, nx);
  fnResult(voDFSrch);

  return 0;
}