Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
//if it is not fully connected component
#define N 105
vector<int> nebors[N];//start from 1
int start[N]; // start form 1
int end[N]; //end with 1
int vis_nei[N]; // neighbor
stack<int> s;
int dfs(int k,int d){
	start[k] = (++d);

	for(int i = 0; i<nebors[k].size(); i++){
		int temp = nebors[k].at(i);
		if(start[temp]==-1) d = dfs(temp,d);
	}
	end[k] = (++d);
	return d;
}

int main(){
	int n;
	scanf("%d",&n);
	memset(start,-1,sizeof(start));
	memset(end,-1,sizeof(end));
	memset(vis_nei,-1,sizeof(vis_nei));
	//vis_nei
	for(int i = 1; i<=n; i++){
		int id,num;
		scanf("%d %d",&id, &num);
		for(int j = 0; j<num; j++){
			int temp;
			scanf("%d",&temp);
			nebors[id].push_back(temp);
			//nebors[temp].push_back(id);
		}
	}
	//check each node for the (unfully connected)
	int d = 0;
	for(int i = 1; i<n; i++){
		if(start[i]==-1){
			d = dfs(i,d);
		}
	}
	
	for(int i = 1; i<=n; i++){
		printf("%d %d %d\n",i,start[i],end[i]);
	}
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
#define int ll

int g[105][105], d[105], f[105];
int presenttime = 1, n;
bool is_search[105];

void bfs(int p) {
  d[p] = presenttime++;
  is_search[p] = true; // ??????????????§?????§??????

  for (int i = 0; i < n; i++) {
    if(is_search[i] == false && g[p][i] && p != i) bfs(i);
  }
  if (f[p] == 0) f[p] = presenttime++;
}

signed main(void) {
  int u, k, v;

  fill(is_search, is_search + n, false);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int i = 0; i < k; i++) {
      cin >> v;
      g[u-1][v-1] = 1;
    }
   }

  int s = 0, i;

   while(1) {
    s = 0;
    bfs(s);

    for (i = 0; i < n; i++) {
      if (is_search[i] == false) {
        s = i;
        break;
      }
    }
    if(i == n) break;
   }

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

C++: #include<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];

void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++)
      cin>>v,e[u-1][v-1]=1;
  }
  cnt=1;
  dfs(0);
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;
  }
  return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

int n;
int graph[MAX][MAX];
stack<int> st;
int *d,*f,*v;
int *color;
int t = 0;

int next(int k){
	for(int i = v[k];i < n;i++){
		v[k]++;
		if(color[i] == WHITE && graph[k][i] == 1) return i;
	}
	return -1;
}

void dfs(int k){
	for(int i = 0;i < n;i++) v[i] = 0;

	st.push(k);
	d[k] = ++t;
	color[k] = GRAY;

	while(!st.empty()){
		int m = next(st.top());
		if(m != -1){
		  if(color[m] == WHITE){
				st.push(m);
				color[m] = GRAY;
				d[m] = ++t;
			}
		}else{
			f[st.top()] = ++t;
			color[st.top()] = BLACK;
			st.pop();
		}
	}
}


int main(){
	cin >> n;
	//?????????
	color = new int[n];
	d = new int[n];
	f = new int[n];
	v = new int[n];
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		d[i] = 0;
		f[i] = 0;
		for(int j = 0;j < n;j++){
			graph[i][j] = 0;
		}
	}
	//data input
	for(int i = 0;i < n;i++){

		int t,k,p;

		cin >> t >>  k;
		for(int j = 0;j < k;j++){
			cin >> p;
			p--;
			graph[i][p] = 1;
		}
	}
	for(int i = 0;i < n;i++){if(color[i] == WHITE) dfs(i);}
	for(int i = 0;i < n;i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];
    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    _dfs(1);
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << start[i] << " " << finish[i] << endl;
    }
}