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++: /* 
 * ALDS1_11B.cpp
 */
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int N;
int ad_k[101];
int ad_list[101][101];

int jikan = 0;
int d[101], f[101];
bool visited[101];

void visit(int id) {
    if (visited[id])
        return;

    visited[id] = true;
    d[id] = ++jikan;
    for (int i = 0; i < ad_k[id]; ++i) {
        visit(ad_list[id][i]);
    }
    f[id] = ++jikan;
}

int main(void) {

    scanf("%d", &N);
    for (int i = 1, id; i <= N; ++i) {
        scanf("%d", &id);
        scanf("%d", ad_k + id);
        for (int j = 0; j < ad_k[id]; ++j) {
            scanf("%d", ad_list[id] + j);
        }
    }

    for (int i = 1; i <= N; ++i) {
        visit(i);
    }

    for (int i = 1; i <= N; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> PP;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[200];
int d[200] = {}, f[200] = {};

int func(int pos, int time){
  if(d[pos] > 0){
    return time;
  }
  d[pos] = time;
  time += 1;
  for(int to : E[pos]){
    time = func(to, time);
  }
  f[pos] = time;
  time += 1;
  return time;
}

int main(){
  int n;
  cin >> n;
  for(int loop = 0; loop < n; loop++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int v;
      cin >> v;
      E[u].push_back(v);
    }
  }
  int time = 1;
  for(int i = 1; i <= n; i++){
    if(d[i] == 0){
      time = func(i, time);
    }
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

struct Edge
{
	int to;
};

vector<vector<int>> DFS(vector<vector<Edge>>& G)
{
	int timecounter = 0;
	int next = 1;
	vector<vector<int>> result;
	result = vector<vector<int>>(2, vector<int>(G.size(), 0));
	vector<int> prev(G.size(),0);
	
	while(result[1][0] == 0){
		int tmp;
		if(result[0][next - 1] == 0){
			timecounter += 1;	
			result[0][next - 1] = timecounter;
		}

		if(G[next - 1].empty()){
			if(result[1][next - 1] == 0){
				timecounter +=1;
				result[1][next - 1] = timecounter;
			}
			next = prev[next - 1];
		}else{
			tmp = G[next - 1].begin()->to;
			G[next - 1].erase(G[next - 1].begin());
			prev[tmp - 1] = next;
			next = tmp;
		}
	}
	return result;
}

int main(void)
{
	int n;
	cin >> n;

	vector<vector<Edge>> AdjList(n);
	for(int i = 0; i < n; i++){
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			AdjList[i].push_back(Edge{v});
		}
	}

	vector<vector<int>> timestump = DFS(AdjList);
	
	for(int i = 0; i < AdjList.size(); i++){
		cout << i + 1 << " " << timestump[0][i] << " " << timestump[1][i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

#define MAX 101

using namespace std;

int visited[MAX],d[MAX],f[MAX];
int tt=0;
vector<int> G[MAX];

void dfs(int u){
  d[u]=++tt;
  for(int i=0;i<G[u].size();i++){
    if(visited[G[u][i]]==0) dfs(G[u][i]);
  }
  visited[u]=1;
  f[u]=++tt;
}

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

C++: #include <bits/stdc++.h>
#define REP0(i,n) for(int i=0;i<n;i++)
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
int n,M[N][N];
int color[N],D[N],F[N],tt;
int nt[N];
int next(int u){
  for(int v=nt[u];v<n;v++){
    nt[u]=v+1;
    if(M[u][v]) return v;
  }
  return -1;
}
void DFS_visit(int r){
  REP0(i,n) nt[i]=0;
  stack<int> S;
  S.push(r);
  color[r]=gray;
  D[r]=++tt;
  while(!S.empty()){
    int u=S.top();
    int v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
        color[v]=GRAY;
        D[v]=++tt;
        S.push();
      }
    } else{
      S.pop();
      color[u]=BLACK;
      F[u]=++tt;
    }
  }
}
void DFS(){
  REP0(i,n){
    color[i]=WHITE;
    nt[i]=0;
  }
  tt=0;
  REP0(u,n) if(color[u]==WHITE) DFS_visit(u);
  REP0(i,n) printf("%d %d %d\n",i+1,D[i],F[i]);
}
int main(){
  int u,k,v;
  scanf("%d",&n);
  REP0(i,n){
    REP0(j,n) M[i][j]=0;
  }
  REP0(i,n){
    scanf("%d %d",&u,&k);
    REP(j,k){
      scanf("%d",&v);
      M[--u][--v]=1;
    }
  }
  DFS();
  return 0;
}