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)
	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<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int n = 0;
int u = 0;
int k[101];
int v[101][101];
int Discover[101] = { 0 };
int End[101] = { 0 };
//int nx = 0;
int p = 0;
void dfs(int l) {
	int i;
	int j;
	if (!Discover[l]) {
		Discover[l] = ++p;

		for (i = 0; i < n + 1; i++) {
			if (v[l][i]) {
				dfs(v[l][i]);
			}
		}
		End[l] = ++p;
	}
}
int main()
{
	int i;
	int j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u ;
		cin >> k[u];
		for (j = 0; j < k[u]; j++) {
			cin >> v[u][j];
		}
	}
	for (i = 1; i < n + 1; i++) {
		if (!Discover[i]) {
			dfs(i);
		}
	}
	for (i = 1; i < n + 1; i++) {
		cout << i << " " << Discover[i] << " " << End[i] << endl;
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

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

// u?????£??\??????v?????????????????????
int next(int u){
    for (int v = nt[u]; v < n ; v++) {
        nt[u] = v +1;
        if(M[u][v]) return v;
    }
    return -1;
}

//with stack

void dfs_visit (int r){
    for (int i = 0; i < n ; ++i) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    tt ++; 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(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++ tt;
        }
    }
}

void dfs(){
    int u;
    for (u = 0; u < n; ++u) {
        color[u] = white;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == white) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int u,v,k;
    M[N][N] = {0};
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        u --;
        for (int j = 0; j < k ; ++j) {
            cin >> v;
            v --;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vector< vector<int> > graph(110, vector<int>());
vector<int> fst(110, -1);
vector<int> snd(110, -1);

int abstime = 0;
void dfs(int now) {
    // cout << "ok" << endl;
    if(fst.at(now) != -1) return;
    abstime++;
    fst.at(now) = abstime;
    for(int i = 0; i < graph.at(now).size(); ++i) {
        dfs(graph.at(now).at(i));
    }
    abstime++;
    snd.at(now) = abstime;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            v--;
            graph.at(u).push_back(v);
        }
    }

    for(int i = 0; i < n; ++i) {
        dfs(i);
    }

    for(int i = 0; i < n; ++i) {
        cout << i+1 << " " << fst.at(i) << " " << snd.at(i) << endl;
    }
}

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

using namespace std;

int N;
vector<vector<int>> tree;
vector<pair<int,int>> times;

void stamp(int ind, int &time){
	//cout << ind << "," << time << endl;
	if(times[ind].first == 0) times[ind].first = time++;
	else return;
	if(tree[ind].size() == 0){
		times[ind].second = time++;
		//cout<<"break! " << ind << endl;
		return;
	}
	for(int i=0;i<tree[ind].size();i++){
		//cout << tree[ind][i] << endl;
		stamp(tree[ind][i],time);
	}
	//cout << ind << ":" << time << endl;
	times[ind].second = time++;
}

int main(){
	cin >> N;
	tree = vector<vector<int>>(N+1);
	times = vector<pair<int,int>>(N+1,make_pair(0,0));

	for(int i=1;i<N+1;i++){
		int ind, branch;
		cin >> ind >> branch;
		vector<int> tmp(branch);
		for(int j=0;j<branch;j++){
			int in;
			cin >> in;
			tmp[j] =  in;
		}
		tree[ind] = tmp;
	}

	int time = 1;
	stamp(1,time);

	int i = 1;
	for(auto st:times){
		if(i<=N)
			cout << i << " " << times[i].first << " " << times[i].second << endl;
		i++;
	}

	return 0;
}

C++: /*16D8103008D 西村悠輝　nissy0507barista  alds11_B*/ 

#include<iostream>

#define MAX 100
using namespace std;

int n,v,k,u; ///超点数、頂点番号、出次数、隣接
int d[MAX], f[MAX];///タイムスタンプ
int a[MAX][MAX];
int cnt=0;
int flag[MAX]; ///通ったかどうか

void dfs(int x) {

	if (flag[x] == 1)return;
	cnt++;
	d[x] += cnt;
	flag[x] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[x][i] == 1 && flag[i] == 0) dfs(i);
	}
	cnt++;
	f[x] += cnt;

}

int main(void)
{
	cin >> n;

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

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

	return 0;
}