Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

C++: #include<iostream>
#include<vector>
#include<limits.h>
#include<stack>
#include<string>
using namespace std;

struct Vertex{
	int deg;
	vector<int> adj;
	int checked;
	int parent;
};

int out(vector<int> &A){
	int n=A.size();
	int i;
	if (n==0){
		cout << "nothing" <<endl;
	}else if(n==1){
		cout << A[0] << endl;
	}else{
		for (i=0;i<=n-2;i++){
			cout << A[i] << " ";
		}
		cout << A[n-1] <<endl;
	}
}

int Next(vector<Vertex> &L,vector<int> &d, vector<int> &f, int cur, int count){
	int next,i,v;
	if(L[cur].deg==0){
		next=L[cur].parent;
		f[cur]=count;
		return next;
	}
	
	for (i=0;i<L[cur].deg;i++){
		v=L[cur].adj[i];
		if(L[v].checked==0){
			break;
			}
		}
		if(i==L[cur].deg){
			next=L[cur].parent;
			f[cur]=count;
		}else{
			next=v;
			L[next].parent=cur;
			L[next].checked=1;
			d[next]=count;
		}
	return next;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,i,j;
	cin >> n;
	
	vector<Vertex> L(n);
	vector<int> d(n);
	vector<int> f(n);
	
	int id,de,v;
	for (i=0;i<n;i++){
		cin >> id >> de;
		L[id-1].deg=de;
		for (j=0;j<de;j++){
			cin >> v;
			L[id-1].adj.push_back(v-1);
		}
		L[id-1].checked=0;
		L[id-1].parent=-1;
	}
	
	int cur=0;
	int next,count=0;
	
	while(1){
		count++;
		for (i=0;i<n;i++){
			if(L[i].checked==0){
				break;
			}
		}
		if (i==n){
			break;
		}
		L[i].checked=1;
		d[i]=count;
		cur=i;
		while(1){
			count++;
			next=Next(L,d,f,cur,count);
			if (next==-1){
				break;
			}
			cur=next;
		}
		}
	for (i=1;i<n+1;i++){
		cout << i << " " << d[i-1] << " " << f[i-1] <<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
int n;
int m[N][N];
int used[N];
int time = 1;
int _start[N];
int _end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    _start[root] = time++;
    stack<int> s;
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            _start[v] = time++;
            s.push(v);
        } else{
            _end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, _start[i], _end[i]);
    }
    return 0;
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define debug(x) cout<< #x <<": "<<x<<endl
#define debug2(x,y) cout<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

vi ts_d;
vi ts_f;

template<class T>
void dfs(int cur, int &time_visit, T graph) {
  // visiting cur
  time_visit += 1;
  ts_d[cur] = time_visit;
  for (auto dst : graph[cur]) {
    if (ts_d[dst] == 0) {
      dfs(dst, time_visit, graph);
    }
  }
  time_visit += 1;
  ts_f[cur] = time_visit;
  return;
}

int main() {
  int time = 0;
  int n;
  cin >> n;
  ts_d.reserve(n);
  ts_f.reserve(n);
  ts_d.assign(1, 0);
  vector<set<int> > graph(n, set<int>());

  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    num -= 1;
    int out;
    cin >> out;
    for (int j = 0; j < out; ++j) {
      int tmp;
      cin >> tmp;
      tmp -= 1;
      graph[i].insert(tmp);
    }
  }

  for (int i = 0; i < n; ++i) {
    if (ts_d[i] == 0) {
      dfs(i, time, graph);
    }
  }

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

  return 0;
}

C++: #include<stdio.h>
int d[101],e[101],t=0,n;
bool went[101],graph[101][101];
void dfs(int x){
    if(went[x])return;
    went[x]=true;
    t++;
    d[x]=t;
    for(int i=1;i<=n;i++){if(graph[x][i])dfs(i);}
    t++;
    e[x]=t;
    return;
}

int main(){
    int m,temp,a;
    scanf("%d",&n);
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++)graph[i][j]=false;
        went[i]=false;
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&m);
        for(int j=0;j<m;j++){
            scanf("%d",&temp);
            graph[a][temp]=true;
        }
    }
    for(int i=1;i<=n;i++)dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],e[i]);
}