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 <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = search(array, A, 1, n, 0);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}

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

vector<int>G[102];
int d[102],f[102];
bool vis[102];
int V;
int cur=0;
/*
void dfs(int id){
    cur++;
    d[id]=cur;
    vis[id]=true;
    for(int i=0;i<G[id].size();i++){
        if(!vis[G[id][i]])
            dfs(G[id][i]);
    }
    f[id]=cur;
}
*/
stack<int> s;
void dfs_visit(int id){
    s.push(id);
    cur++;
    d[id]=cur;
    while(!s.empty()){
        int u=s.top();
        int nex=-1;
        for(int i=0;i<G[u].size();i++){
            if(!vis[G[u][i]]) {
                nex=G[u][i];
                break;
            }
        }
        cur++;
        if(nex==-1){
            s.pop();
            f[u]=cur;
            vis[u]=true;
        }
        else{
            d[nex]=cur;
            s.push(nex);
        }
    }
}

void dfs(){
	int i;
    for(i=1;i<=V;i++){
        if(!vis[i]) dfs_visit(i);
    }
    for(i=1;i<=V;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}
int main(){
    cin>>V;
    memset(vis,false,sizeof(vis));
    for(int i=1;i<=V;i++){
        int id,k;
        cin>>id>>k;
        while(k--){
            int out;
            cin>>out;
            G[id].push_back(out);
        }
        sort(G[id].begin(),G[id].end());
    }
    dfs();
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int map[255][255];
int f[255],d[255],tt=0;
bool vis[255];
void dfs(int n,int u)
{
	if(vis[u]) return;
	vis[u]=true;
	tt++;
	d[u]=tt;
	for(int i=1;i<=n;i++)
	{
		if(map[u][i]) dfs(n,i);
	}
	tt++;
	f[u]=tt;
	return; 
}
int main()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			map[i][j]=0;
		}
	for(int i=0;i<n;i++)
	{
		int cur,k,u;
		cin>>cur>>k;
		while(k--)
		{
			cin>>u;
			map[cur][u]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		vis[i]=false;
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) dfs(n,i);
	}
	for(int i=1;i<=n;i++)
	{
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cassert>
#include <string.h>
#include <vector>
#include <map>
#include <stack>

enum Color
{
    kWhite,
    kGray,
    kBlack,
};

// 頂点数.
int n;

// 各頂点の隣接リスト表現.
std::map< int, std::vector<int> > adj_list;

// 各頂点の訪問状態を管理する.
std::vector<Color> c;

// 初回訪問時.
std::vector<int> d;

// 二回目訪問時.
std::vector<int> f;

void makeAdjListFromInput(int n)
{
    for (int i = 0; i < n; ++i)
    {
        int vertex;
        int degree;

        std::cin >> vertex;
        std::cin >> degree;

        assert(vertex <= n);
        assert(degree <= n);

        std::vector<int> adj_vertexes;

        for (int j = 0; j < degree; ++j)
        {
            int adj;
            std::cin >> adj;
            adj_vertexes.push_back(adj - 1);
        }

        adj_list[vertex - 1] = adj_vertexes;
    }
}

int nextVertex(int current)
{
    std::vector< int > adjs = adj_list[current];
    for (std::vector< int >::iterator it = adjs.begin(); it != adjs.end(); ++it)
    {
        if (c[(*it)] == kWhite)
            return (*it);
    }

    // 見つからなかった.
    return INT_MAX;
}

int firstVertex()
{
    for (int i = 0; i < n; ++i)
    {
        if (c[i] == kWhite)
            return i;
    }

    return INT_MAX;
}

void depthFirstSearch()
{
    int counter = 0;
    std::stack<int> tmp_stack;

    // 諸々初期化.
    for (int i = 0; i < n; ++i)
    {
        c.push_back(kWhite);
        d.push_back(0);
        f.push_back(0);
    }

    while (true)
    {
        int first = firstVertex();
        if (first == INT_MAX)
            break;
        tmp_stack.push(first);
        c[first] = kGray;
        d[first] = ++counter;

        while (! tmp_stack.empty())
        {
            int current = tmp_stack.top();
            int next = nextVertex(current);
            if (next != INT_MAX)
            {
                tmp_stack.push(next);
                c[next] = kGray;
                d[next] = ++counter;
            }
            else
            {
                int pop = tmp_stack.top();
                tmp_stack.pop();
                c[pop] = kBlack;
                f[pop] = ++counter;
            }
        }
    }
}

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

    makeAdjListFromInput(n);

    depthFirstSearch();

    for (std::map< int, std::vector<int> >::iterator it = adj_list.begin(); it != adj_list.end(); ++it)
    {
        int v = it->first;
        std::cout << v + 1 << " " << d[v] << " " << f[v] << std::endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
typedef struct Node{
  vector<int> to;
  int d;
  int f;
}Node;

int n;
Node G[110];
int t = 0;

void dfs(int v){
  if(G[v].d > 0) return;
  G[v].d = ++t;
  for(int i=0; i<G[v].to.size(); i++){
    dfs(G[v].to[i]);
  }
  if(G[v].f < 0) G[v].f = ++t;
  return;
}

int main(){
  cin >> n;
  for(int i=0; i<n; i++){
    int u, k; cin >> u >> k;
    Node v;
    v.d = -1;
    v.f = -1;
    for(int j=0; j<k; j++){
      int c; cin >> c;
      v.to.push_back(c-1);
    }
    G[u-1] = v;
  }
  for(int i=0; i<n; i++){
    dfs(i);
  }
  for(int i=0; i<n; i++){
    cout << i+1 << " " << G[i].d << " " << G[i].f << endl;
  }
}