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 <iostream>
#include <vector>
#include <list>
#include <cstdlib>

const int MAX_N = 100;

struct Node {
  int v;
  int firstVisitedTime;
  int lastVisitedTime;
  bool visited;
  bool opened;
};

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

  int n = 0;
  std::cin >> n;

  std::vector<std::list<int> *> *graph = new std::vector<std::list<int> *>(n + 1);
  std::vector<struct Node *> *nodes = new std::vector<struct Node *>(n + 1);
  
  for (int i = 1; i <= n; i++) {
    int v = 0;
    std::cin >> v;

    int k = 0;
    std::cin >> k;

    std::list<int> *neighbors = new std::list<int>();

    for (int j = 0; j < k; j++) {
      int a = 0;
      std::cin >> a;

      if (v == j) {
	continue;
      }

      neighbors->push_back(a);
    }

    graph->at(i) = neighbors;

    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->v = i;
    node->firstVisitedTime = 0;
    node->lastVisitedTime = 0;
    node->visited = false;
    node->opened = false;
    
    nodes->at(i) = node;
  }
  
  std::list<int> *stack = new std::list<int>();

  
  int start = 1;
  
  stack->push_front(start);
  
  nodes->at(start)->firstVisitedTime = 1;
  nodes->at(start)->lastVisitedTime = 1;

  int count = 0;

  while (!stack->empty()) {
    count++;
    
    int n = stack->front();
    struct Node *node = nodes->at(n);

    if ((node->visited) && (!node->opened)) {
      count--;
    }
    
    if (!node->visited) {
      node->firstVisitedTime = count;
      node->visited = true;
    }
    
    //std::cout << count << " = " << n << std::endl;
    
    if (node->opened) {
      node->lastVisitedTime = count;
       
      stack->pop_front();

      if (stack->empty()) {
	for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
	  struct Node *node = *iterator;

	  if (!node->visited) {
	    nodes->at(node->v)->firstVisitedTime = count;
	    nodes->at(node->v)->lastVisitedTime = count;

	    stack->push_back(node->v);

	    break;
	  }
	}	
      }
      
      continue;
    }
    
    std::list<int> *neighbors = graph->at(n);

    while (!neighbors->empty()) {
      int v = neighbors->front();
      neighbors->pop_front();

      if (!nodes->at(v)->visited) {
	stack->push_front(v);

	break;
      }
    }

    if (neighbors->empty()) {
      node->opened = true;
    }
  }

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
        
    std::cout << node->v << " " << node->firstVisitedTime << " " << node->lastVisitedTime << std::endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[now]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define W 0
#define B 1
#define G 2
#define rep(i,a) for(i=1;i<=a;i++)
using namespace std;

vector <vector<int> > A;
vector <int> c;
vector <int> d;
vector <int> f;
vector <int> k;

int n,u,t;

void visit(int r) {
    int i;
    c[r] = G;
    d[r] = ++t;
    rep(i,k[r]){
        if(c[A[r][i]] == W) visit(A[r][i]);
    }
    c[r] = B;
    f[r] = ++t;
}

void dfs(void){
    int i;
    rep(i,n) 
        c[i] = W;
    t = 0;
    rep(i,n){
        if(c[i] == W) visit(i);
    }
}

int main(void){
    int i,j;
    cin >> n;
    c.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);
    k.resize(n+1);
    A.resize(n+1);
    rep(i,n) A[i].resize(n+1);
    rep(i,n){
        cin >> u >> k[i];
        rep(j,k[i]){
            cin >> A[i][j];
        }
    }
    dfs();
    rep(i,n){
        cout << i << " " <<d[i] << " "<< f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int visited[100]={0};
int V[100][100]={0};
int start[100]={0};
int finish[100]={0};
int t=1;

void dfs(int i,int n){
  start[i]=t++;
  visited[i]++;
  for(int j=0;j<n;j++){
    if(V[i][j]==1 and visited[j]==0){
      dfs(j,n);
    }
  } 
  finish[i]=t++;
}



int main () {
    int n,k;
    int p1, p2;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            V[i][j] = 0;
        }
  }
  for(int i=0;i<n;i++){
    cin>>p1>>k;
    for(int j=0;j<k;j++){
      cin>>p2;
      V[p1-1][p2-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visited[i]==0){
      dfs(i,n);
    }
  }
  for(int i=0;i<n;i++){
      cout << i + 1 << " ";
      cout<<start[i] << " " << finish[i] << "\n";
  }


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1

// グラフの隣接頂点リスト表現
struct GraphAV{
    int p;  // 頂点数
    int q;  // 辺数
    // int AV[VMAX][DMAX]; 
    vector<vector<int>> AV;  // 隣接頂点リスト
};

GraphAV G;
// int d[VMAX],f[VMAX];
// bool seen[VMAX];
vector<int> d(VMAX);
vector<int> f(VMAX);
vector<bool> seen(VMAX);
int t=1;
void DFS(int v,int& t);

int main(){
    cin>>G.p;

    d.resize(G.p+1);
    f.resize(G.p+1);
    G.AV.resize(G.p+1);
    seen.resize(G.p+1);
    G.AV[0]={NOTUSED};
    d[0]=NOTUSED;
    
    for(int i=1; i<=G.p; i++){
        int u,k;
        cin>>u>>k;
        G.AV[u].resize(k);
        for(int j=0; j<k; j++){
            cin>>G.AV[u][j];
        }
    }

    for(int i=1; i<=G.p; i++){
        if(seen[i]){
            continue;
        }
        DFS(i,t);
    }

    for(int i=1; i<=G.p; i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

void DFS(int v,int& t){
    d[v]=t++;

    seen[v]=true;
    // v から行ける各頂点 adj_v について
    for(int adj_v:G.AV[v]){
        if(seen[adj_v]) continue; // adj_v が探索済なら何もしない
        DFS(adj_v,t);  // 再帰的に探索
    }

    f[v]=t++;
}