Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u[200],k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
int Gcounter;
int Fcounter;
int Find;
void dfs(int where){
  fincou++;
  Fcounter++;

  GetIt[where]=Find;
 
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[imap[where][i]]){
	Gcounter++;
	Find++;

	used[imap[where][i]] = true;
	dfs(imap[where][i]);
	fincou++;
	Fcounter++;

      }
    }
  }
    FinIt[where] = fincou;
     
}
 
int main(){
  
  int ad;
   
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u[i];
    cin >> k[u[i]];
    for(int j=0;j<k[u[i]];j++){
      cin >> ad;
      imap[u[i]][j] = ad;
    }
  }
 
 
  for(int j=0;j<200;j++)used[j] = false;
  Gcounter=Fcounter=1;
 
  Find = 1;
  int Index=0;
  bool fin = true;
  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	//used[u[i]]=true;
      dfs(u[i]);
      Find = fincou+1;
      fincou++;      
    
      }
    }
  
  //dfs(u[0]);   

   
  
  //cout << "counter - " << Find << ", F" << fincou << endl;
  for(int i=0;i<n;i++){
    cout << i+1 << " " << GetIt[i+1]  << " " << FinIt[i+1];
    cout << endl;
  }
 
  return 0;
}

C++: #include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    for (int j = 1; j <= n; ++j) {
        if (G[i][j] != -1 && STATE[j] != NOT_VISIT) continue;
        dfs(j);
    }
    STATE[i] = FOUND;
    f[i] = ++tt;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

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

int t = 0;

class Node{
  public:
  int _id, _findTime, _finishTime;
  vector<int> _edgeId;  // 隣接する頂点
  int _isFound;

  void init(){
    int dim;
    _findTime = _finishTime = 0;
    _isFound = false;
    cin >> _id >> dim;

    for(auto j = 0; j < dim; j++){
      int in;
      cin >> in;
      _edgeId.push_back(in);
    }
  }
};

void DepthFirstSearch(vector<Node>& vertices, int key){
  vertices[key]._isFound = true;
  vertices[key]._findTime = ++t;
  for(auto i = 1; i < vertices.size(); i++){
    auto result = find(vertices[key]._edgeId.begin(), vertices[key]._edgeId.end(), i);
    if(result == vertices[key]._edgeId.end()) continue;
    if(!vertices[i]._isFound){
      DepthFirstSearch(vertices, i);
    }
  }
  vertices[key]._isFound = true;
  vertices[key]._finishTime = ++t;
}

void PrintResult(vector<Node> vertices){
  for(auto i = 1; i < vertices.size(); i++){
    cout << vertices[i]._id << " " << vertices[i]._findTime << " " << vertices[i]._finishTime << '\n';
  }
}

int main(){
  int n;
  cin >> n;
  vector<Node> vertices(n + 1);

  for(auto i = 1; i <= n; i++){
    vertices[i].init();
  }

  for(auto i = 1; i <= n; i++) {
    if(!vertices[i]._isFound)
      DepthFirstSearch(vertices, i);
  }
  PrintResult(vertices);

  return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
// stackのパターン
// 実習資料では「srcの訪問時刻は0」となっているが、題意は1である。

#include <iostream>
#include <cstdio>
#include <stack> // 入れたものから出していく引っ越しトラック型の構造。
using namespace std;

int G[110][110];
int n;
int u, k, v;

void make_matrix() {
  fill(&G[0][0], &G[0][0]+110*110, 0);
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d", &u, &k);
    u--;
    for (int j=0; j<k; j++) {
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
}

int timer; // timeだとエラーが出たので。
int d[110]; // 訪問時刻。ナマの数字を入れる(indexを-1処理しない)。
int f[110]; // 終了時刻。ナマの数字を入れる。
int parent[110]; // 訪問する原因となった数字を入れる。ナマの数字を入れる。

void init() {
  timer = 1;
  fill(d, d+110, -1);
  fill(f, f+110, -1);
  fill(parent, parent+110, -1);
}

void dfs(int src) {
  cerr << "dfs root is " << src << endl;
  stack<int> S; // todo訪問先
  S.push(src);
  while (! S.empty()) {
    int cur = S.top(); // 一番最近入れた数字を訪問しようとする。
    S.pop();
    if (d[cur] != -1) { // 過去訪問した場合は、訪問しない。
      continue;
    }
    d[cur] = timer;
    timer++;
    cerr << "visiting " << cur << " at the time " << d[cur] << endl;
    for (int i=n; i>=1; i--) { // 節点i。逆順に入れていくことに注意！
      if (G[cur-1][i-1] == 1 && d[i] == -1) {
	S.push(i);
	cerr << "pushing " << i << endl; 
	parent[i] = cur;
        cerr << "parent[" << i << "] is " << cur << endl;
      }
    }
    int hantei = cur;
    int modoru = -1;
    while (! S.empty() && d[S.top()] != -1) {
      S.pop();
    }
    if (! S.empty()) {
      modoru = parent[S.top()];
    }
    while (hantei != modoru) {
      cerr << "hantei " << hantei << " modoru " << modoru << endl; 
      f[hantei] = timer;
      timer++;
      hantei = parent[hantei];
      cerr << "hantei " << hantei << endl;
    }
  }
}

int main() {
  make_matrix();
  init();
  for (int i=1; i<=n; i++) { // 1から連結していない連結成分にも番号をふる。
    if (d[i] == -1) {
      dfs(i);
    }
  }
  for (int i=1; i<=n; i++) {
    printf("%d %d %d\n", i, d[i], f[i]);
  }
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
mat g;
vll d;
vll f;
vbl vis;

lli u,k,v;
lli t = 0;

lli dfs(lli x,lli t){
    d[x] = t;
    vis[x] = true;
    for(lli i = 0;i < g[x].size();i++){
        if(!vis[g[x][i]]) t = dfs(g[x][i],t+1);
    }
    return f[x] = t + 1;
}

int main(){
    cin >> n;
    g = mat(n+1);
    d = vll(n+1);
    f = vll(n+1);
    vis = vbl(n+1);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v;
            g[u].push_back(v);
        }
    }
    for(lli i = 1;i <= n;i++){
        if(!vis[i]) t = dfs(i,t+1);
    }
    for(lli i = 1;i <= n;i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}