Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

  for(int i=1;i<=n;i++){
    printf("%d %d %d", v[i].id, v[i].d, v[i].f);
    if(i != n)printf("\n");
  }
  return 0;
}

C++: #include<iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt;
 
    for(v=0; v<n; v++){
        if(M[u][v]==0){continue;}
        if(color[v]==WHITE){dfs_visit(v);}
    }
    color[u]=BLACK;
    f[u]=++tt;
}

void dfs(){
    int u;
 
    for(u=0; u<n; u++){
        color[u]=WHITE;
    }
    tt=0;
    for(u=0; u<n; u++){
        if(color[u]==WHITE){dfs_visit(u);}
    }
    for(u=0; u<n; u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

int main(){
    int i,j,k,u,v;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j]=0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    dfs();
    return 0;
}

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

int n,v,u,k,Time,data[101][101],d[101],f[101];

//dfs
void visit(int u){
  int v;
  d[u] = Time++;
 
  for(v = 1; v <= n; v++){
    if(data[u][v]&d[v]==0)
      visit(v);
  }
  f[u] = Time++;
}
 
int main(){
  cin >> n;
  
  //初期化
  Time = 1;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      data[i][j]=0;
      d[j]=0;
      f[j]=0;
    }
  }
  
  //入力
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      data[u][v]=1;
    }
  }
  
  //dfs
  for(int i = 1;i <= n; i++){
    if(d[i]==0)visit(i);
  }
  
  //出力
  for(int i = 1;i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define MAX 100
#define FND -1
#define CMP -2

int n, G_list[MAX+1];
int G[MAX+1][MAX+1];
int d[MAX+1][3];

void make_graph(void){
  scanf("%d", &n);

  for(int i=0; i<n; i++){
    int cnt, num, m;

    scanf("%d %d", &num, &cnt);
    G_list[i]=num;

    for(int j=0; j<cnt; j++){
      scanf("%d", &m);
      G[num][m]=1;
    }
  }
}

void check_depth(int data){
  stack<int> S;
  static int tm=0;
  
  S.push(data);
  d[data][0]=++tm;
  d[data][2]=FND;
  
  while(!S.empty()){
    int top=S.top();
    int next=-5;

    for(int i=0; i<n; i++){
      if(G[top][G_list[i]] == 1 && d[G_list[i]][2] == 0){
	next=G_list[i];
	S.push(next);
	d[next][2]=FND;
	d[next][0]=++tm;
	break;
      }
    }

    if(next == -5){
      d[S.top()][2]=CMP;
      d[S.top()][1]=++tm;
      S.pop();
    }

  }
}

void set_depth(void){

  for(int i=0; i<n; i++){
    if(d[G_list[i]][2] == 0) check_depth(G_list[i]);
  }
}

void print(void){

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

int main(void){

  make_graph();
  set_depth();
  print();
  
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
using namespace std;

int t = 1;
int first[101] = {0};
int last[101] = {0};
void dfs(vector<vector<int> > &graph, int v, set<int> &seen){
	seen.insert(v);
	first[v] = t;
	t++;
	for (int i=0;i<graph[v].size();i++){
		int nxt = graph[v][i];
		if (seen.count(nxt)) continue;
		dfs(graph, nxt, seen);
	}
	last[v] = t;
	t++;
}



int main(){
	int n; cin >> n;
	vector<vector<int> > graph(n+1);
	for (int i = 0; i < n; i++){
		int v, k; cin >> v >> k;
		for (int j = 0; j < k; j++) {
			int in; cin >> in;
			graph[v].push_back(in);
		}
	}

	set<int> seen;
	for (int i=1;i<n+1;i++){
		if (seen.count(i)) continue;
		dfs(graph,i,seen);
	}


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

	return 0;
}