Go: #include <bits/stdc++.h>
using namespace std;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int N     = 100;

int n, tt;
vector<vector<int>> M(N, vector<int>(N));
vector<int> color(N), d(N), f(N);

void dfs_visit(int u) {
  color[u] = GRAY;
  d[u]     = ++tt;
  for (int 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() {
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k;
  cin >> n;
  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();
}

C++: 
#include<iostream>
#include<stack>
using namespace std;
#define NIL -999
bool mark[105][105];
int n;
int tm = 0;
int d[105] = { 0 };
int f[105] = { 0 };

inline int next(int i) {
	for (int tmp = 1; tmp <= n; ++tmp) {
		if (mark[i][tmp] && !d[tmp]) {
			//cout << endl << i << "的下一个节点是：" << tmp << endl;
			return tmp;
		}
	}
	//cout << endl << i << "的下一个节点是：" << NIL << endl;
	return NIL;
}

void dfs_IN(int i) {
	stack<int> s;
	int now = i, nt;
	d[i] = ++tm;
	s.push(i);
	//	s.push(i);
	//	d[i] = ++tm;
	//first solution
	/*do {
		//		cout<<"visit: "<<now<<endl;
		if (!s.empty()) {
			now = s.top();
			s.pop();
		}
		do {
			//cout << "visit: " << now << endl;
			nt = next(now);
			if (nt != NIL && !d[nt]) {
				s.push(now);
				d[nt] = ++tm;
				now = nt;
			}
			else break;
		} while (true);
		//cout << "end visit:  " << now << endl;
		f[now] = ++tm;
		
	} while (!s.empty());*/
	//solution 2
	while (!s.empty()) {
		now = s.top();
		nt = next(now);
		if (nt != NIL) {
			d[nt] = ++tm;
			s.push(nt);
		}
		else {
			s.pop();
			f[now] = ++tm;
		}
	}
}

void dfs() {
	for (int i = 0; i <= n + 2; ++i)
		for (int k = 1; k <= n + 2; ++k)
			mark[i][k] = false;

	int Node, k, tmp;
	cin >> n;
	for (int l = 0; l<n; l++) {
		cin >> Node >> k;
		for (int x = 0; x<k; x++) {
			cin >> tmp;
			mark[Node][tmp] = true;
		}
	}

	for (int p = 1; p <= n; ++p)
		if(!d[p])dfs_IN(p);

	for (int p = 1; p <= n; ++p)
		cout << p << ' ' << d[p] << ' ' << f[p] << endl;

}

int main() {

	dfs();
	return 0;
}

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

#define NIL 0

struct Node{
    int d=0, f=0, ch=0;
    int child[100]={0};
};

Node nodes[101];

int search(int num, int time){
    if(nodes[num].d!=NIL){
        return time;
    }
    nodes[num].d = time;
    ++time;
    for(int i=0;i<nodes[num].ch;++i){
        time = search(nodes[num].child[i], time);
    }
    nodes[num].f = time;
    ++time;
    return time;
}

int main(){
    
    int n, num=0, time = 1;
    cin >> n;
    for(int i=1;i<=n;++i){
        cin>>num;
        cin >> nodes[num].ch;
        for(int j=0;j<nodes[num].ch;++j){
            cin >> nodes[num].child[j];
        }
    }
    
    
    for(int i=1;i<=n;++i){
        if(nodes[i].d==NIL){
            time = search(i, time);
        }
    }
    
    
    for(int i=1;i<=n;i++){
        cout << i << " " << nodes[i].d << " " <<nodes[i].f << endl;
        
    }
    
    
    
    return 0;
}

C++: #include<iostream>
using namespace std;
typedef struct{
  int A[1000];
  int begin;
  int end;
}node;
node T[105];
int times=0;
  int n;
void function(int num){
  if(T[num].begin==0){
  times++;
    T[num].begin=times;
  }
  for(int j=1;j<=n;j++){
    if(T[num].A[j]==1){
      T[num].A[j]=0;
      function(j);
    }
  }
  if(T[num].end==0){
    times++;
    T[num].end=times;
  }
}
int main(){
  int num;
  int son;
  int z;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num;
    cin>>son;
    for(int j=0;j<son;j++){
      cin>>z;
      T[num].A[z]=1;
      }
  }
  for(int i=1;i<=n;i++){
    function(i);
  }
  for(int i=1;i<=n;i++){
      cout<<i<<" "<<T[i].begin<<" "<<T[i].end<<endl;
  }


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

vector<int> d, f;
int g[111][111];
int n;
int cnt;

void dfs(int now){
  bool flag = false;
  if(d[now] != 0) flag = true;
  else{
    cnt++;
    d[now] = cnt;
  }
  for(int i = 1; i <= n; i++){
    if(g[now-1][i-1] == 1 && d[i] == 0){
      dfs(i);
    }
  }
  cnt++;
  if(flag) cnt--;
  if(f[now] == 0) f[now] = cnt;
}

int main(){

  memset(g,0,sizeof(g));
  d.resize(111);
  f.resize(111);
  cin >> n;

  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    for(int i = 0; i < b; i++){
      int c;
      cin >> c;
      g[a-1][c-1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    dfs(i+1);
  }

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





}

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)
{
    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 a,b,c;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        a--;
        for(int i=0;i<b;i++)
        {
            scanf("%d",&c);
            c--;
            M[a][c]++;
        }
    }
    dfs();
    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

ll d[100], f[100], now, cnt;
char flag[100];
vector<int> vec[100];

int dfs(int n) {
  if(flag[n]) return 0;
  flag[n] = 1;
  cnt++;
  d[n] = cnt;
  vector<int>::iterator it;
  for(it = vec[n].begin(); it != vec[n].end(); ++it) {
    if(!flag[*it]) dfs(*it);
  }
  ++cnt;
  f[n] = cnt;
  return 0;
}

int main(void) {
  ll n;
  scanf("%d", &n);
  now = 0, cnt = 0;
  rep(i, n) flag[i] = 0;
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
    sort(vec[u].begin(), vec[u].end());
  }
  now = 0;
  while( 1 ) {
    dfs(now);
    int s = 1, i;
    for(i = 0; i < n; ++i) if(!flag[i]){
      s = 0;
      break;
    }
    if(s) break;
    else now = i;
    //rep(j, n) printf("%d ", (int)flag[j]);
    printf("%d\n", i);
    //return 0;
  }
  rep(i, n) printf("%d %lld %lld\n", i + 1, d[i], f[i]);
  return 0;
}

C++: //
//  main.cpp
//  DFS
//
//  Created by 2594345669 on 2016/12/05.
//  Copyright ?? 2016??´ as. All rights reserved.
//

#include <iostream>
using namespace std;

typedef pair<int, int> edge;

int vernum[101];
edge path[101][101];
int n;

edge found[101];

int t=1;
void dfs(int v){
    found[v].first = t;
    int i=0;
    while(1){
        if(!path[v][i].first)
            break;
        if(!found[path[v][i].second].first){
            t++;
            dfs(path[v][i].second);
            t++;
        }
        i++;
    }
    found[v].second = t+1;
}

int main() {
    int i, j;
    ios_base::sync_with_stdio(0);
    
    int e, v;
    cin >> n;
    
    for(i=1; i<=n; i++){
        cin >> vernum[i];
        cin >> e;
        for(j=0; j<e; j++){
            cin >> v;
            path[i][j] = make_pair(i, v);
        }
    }
    
    for(i=1; i<=n; i++){
        if(!found[i].first)
            dfs(i);
    }
    
    for(i=1; i<=n; i++){
        cout << vernum[i] << " " << found[i].first << " " << found[i].second << endl;
    }
    
    
    return 0;
}