Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>


using namespace std;

int N;
int D[100+10] = {};
int U = 0;
int K[100+10] = {0};
int V = -1;
int G[100+10][100+10] = {0};
int curtime_st[100+10] = {0};
int curtime_en[100+10] = {0};



//stack dst   queue bfs


int time_ = 1;
int prev1 = 0;
int prev_b = 0;
void dfs(int cur){
  if (cur == -1)return;//??¢??±
  if (curtime_st[cur] == 0)curtime_st[cur] = time_;

  D[cur] = 0;
  time_ += 1;
  //
  //cerr << "visiting " << cur << " " << time_ - 1  << endl;
  
  for(int dst=1;dst<=N;++dst){
    if(D[dst] == -1 && G[cur][dst] == 1){
      dfs(dst);
	}
  }
  if(curtime_en[cur] == 0 || curtime_en[cur] == curtime_st[cur])curtime_en[cur] = time_;
  time_ += 1;
  return;
}







int main(){
  cin >> N;

  for(int i=0;i<101;++i){
    D[i] = -1;//?????????
  }

  for(int i=0;i<N;++i){
    cin >> U;
    cin >> K[U];
    for(int j=0;j<K[U];++j){
      cin >> V;
      G[U][V] = 1;
    }
  }

  for(int j=1;j<=N;++j){
    for(int i=1;i<=N;++i){
      //cout << G[i][j] << " ";
    }
    //cout << endl;
  }

  dfs(1);
  for(int i=2;i<=N;++i){
    if(D[i] == -1)dfs(i);
  }

  for(int i=1;i<=N;++i){
    cout << i << " " << curtime_st[i] << " " << curtime_en[i] << endl; 
  }
}

C++: #include <iostream>

using namespace std;

int graph[101][101]={};
int d[101]={};
int f[101]={};
int n,v,k,time1 = 0,sw[101] = {};


void dfs1(int u){

  sw[u] = 1;
  d[u] = ++time1;

  for(int i = 1; i <= n; i++){
    if( graph[u][i] == 1 && sw[i] == 0 ){
     dfs1(i);
    }

  }
    f[u] = ++time1;
}


int main(){
  int u;
  cin >> n ;
  //グラフをつくる
  for(int i = 0; i < n; i++){
    cin >> u >> k ;
    for(int j = 0; j < k ; j++){
      cin >> v;
      graph[u][v] = 1;
    }
  }
 
 for(int i = 1; i <= n; i++){
    if(sw[i] == 0){
      dfs1(i);
	}
  }

  for(int i = 1; i <= n; i++ ){
    cout << i << ' ' <<  d[i]<< ' ' << f[i] << endl;

  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int t=0;

void dfs(vector<vector<int>> &vec, vector<pair<int, int>> &stmp, int now) {
  if (stmp[now].first) return;
  ++t;
  stmp[now].first = t;

  rep (i, vec[now].size()) dfs(vec, stmp, vec[now][i]);
  

  ++t;
  stmp[now].second = t;
  return;
}
     
int main() {
  int n, k;
  cin >> n;
  vector<vector<int>> vec(n, vector<int>(1));
  vector<pair<int, int>> stmp(n, make_pair(0, 0));
  set<int> s;
  rep (i, n) {
    int voii;
    cin >> voii;
    cin >> k;
    vec[i].resize(k);
    rep (j, k) {
      int x;
      cin >> x;
      vec[i][j] = x - 1;
    }
  }

  rep (i, n) {
    dfs(vec, stmp, i);
  }

  rep (i, n) printf("%d %d %d\n", i + 1, stmp[i].first, stmp[i].second);
}

C++: N = input()
color = [0] * N
d = [0] * N
f = [0] * N
nt = [0] * N
m = [[0] * N for i in range(N)]
S = []
tt = 0

def next(u):
    global nt
    w = nt[u]
    print "w = ",nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1

def dfs_visit(r):
    nt = [0] * N
    global tt 
    S.append(r)
    print S
    color[r] = 1
    tt += 1
    d[r] = tt

    while( len(S) != 0 ):
        u = S[-1]

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
                print S
        else:
            S.pop()
            print S
            color[u] = 2
            tt += 1
            f[u] = tt
        
def dfs():
    global color
    for u in range(N):
        if( color[i] == 0 ):
            dfs_visit(u)

if __name__ == '__main__':

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1
    
    dfs()

    for i in range(N):
        print (i+1), d[i], f[i]

C++: #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;

vector<vector<int>> r(110);
vector<int> d(110),f(110);
int cnt=0;

void dfs(int now) {
    ++cnt;
    d[now]=cnt;
    rep(i,r[now].size()) {
        int next=r[now][i];
        if (d[next]==0) dfs(next);
    }
    ++cnt;
    f[now]=cnt;
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    rep(i,n) {
        int u,k,v;
        cin >> u >> k;
        rep(j,k) {
            cin >> v;
            r[i].push_back(v-1);
        }
    }
    rep(i,n) {
        if (d[i]==0) dfs(i);
    }
    rep(i,n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

    return 0;
}

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

#define MAX 105

struct Point{
    int id;
    int d;
    int f;
    bool flag;
    std::vector<int> child;
};

int stack[MAX];
int sp = 0;
int count = 1;

Point p[MAX];

void push(int id){
    if(p[id].flag == false){
        stack[sp++] = id;
        p[id].d = count++;
        p[id].flag = true;
    }
}

void pop(){
    p[stack[--sp]].f = count++;
    //return stack[sp];
}

void dft(int id){
    //std::cout << id << "に対しdft\n";
    push(id);
    int size = p[id].child.size();
    for(int i=0;i<size;i++){
        if(p[p[id].child[i]].flag == false){
            dft(p[id].child[i]);
        }
    }
    pop();
}

int main(){
    int n;
    int size;
    std::cin >> n;
    for(int i=1;i<=n;i++){
        std::cin >> p[i].id >> size;
        for(int j=0;j<size;j++){
            int tmp;
            std::cin >> tmp;
            p[i].child.push_back(tmp);
        }
    }
    dft(1);
    
    for(int i=1;i<=n;i++){
        std::cout << p[i].id << ' ' << p[i].d << ' ' << p[i].f << '\n';
    }
    
    return 0;
}