Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#define N 100
typedef struct SearchTime SearchTime;

struct SearchTime{
    int find = -1;
    int comp = -1;
    bool flag = false;
    void print(){
        std::cout << find << " " << comp << '\n';
    }
};

int cnt = 1;
SearchTime st[N];

void input_graph(std::vector<std::vector<int> >& Adj, int n){
    int u, k, v;
    for(int i=0; i<n; i++){
        std::cin >> u >> k;
        for(int j=0; j<k; j++){
            std::cin >> v;
            Adj[u-1].push_back(v);
        }
    }
}

void result(int n){
    for(int i=0; i<n; i++){
        std::cout << i+1 << " ";
        st[i].print();
    }
}

void DFS(std::vector<std::vector<int> >& Adj, int n){
    int i = 0;
    int j;
    int nexti;              //毎回-1する.
    std::vector<int> tmp;   //軌跡を保存
    bool newflag = false;
    //深さ優先探索
    while(cnt <= n*2){
        //下層へ探索
        //std::cout << "\nstrat\n";
        newflag = false;
        while(i != -1){
            st[i].flag = true;
            st[i].find = cnt;
            cnt++;
            //std::cout << "cnt:" << cnt-1 << '\n';
            tmp.push_back(i);
            //std::cout << "tmp.size():" << tmp.size() << '\n';
            //std::cout << "i:" << i+1 << '\n';
            //次の葉を探す
            if((int)Adj[i].size() != 0){//葉が最深でないとき
                j = 0;
                nexti = Adj[i][j]-1;
                while(st[nexti].flag){
                    j++;
                    if(j == (int)Adj[i].size()){//もし葉がすべて探索済みなら
                        st[i].comp = cnt;
                        cnt++;
                        //std::cout << "tochu\n";
                        //std::cout << "cnt:" << cnt-1 << '\n';
                        i = -1; //2つ目のwhile文抜ける
                        break;
                    }
                    nexti = Adj[i][j]-1;
                }
                if(i != -1) i = nexti;
            }
            else{//葉が最深のとき
                st[i].comp = cnt;
                cnt++;
                i = -1; //2つ目のwhile文抜ける
                //std::cout << "saishin\n";
                //std::cout << "cnt:" << cnt-1 << '\n';
                //std::cout << "tmp.size():" << tmp.size() << '\n';
                //std::cout << "i:" << i << '\n';
            }
        }
        //ここから根に向かって戻る. 未探索の葉があればそちらへ行く
        //std::cout << "\nback\n";
        tmp.pop_back();
        i = (int)tmp.back();
        tmp.pop_back();
        //std::cout << "tmp.size():" << tmp.size() << '\n';
        //std::cout << "i:" << i+1 << '\n';
        j = 0;
        nexti = Adj[i][j]-1;
        while(st[nexti].flag){
            j++;
            if(j == (int)Adj[i].size()){//現在のノードから未探索の葉がない
                if((int)tmp.size() != 0){//まだtmpに軌跡が残っていれば
                    st[i].comp = cnt;
                    cnt++;
                    //std::cout << "cnt:" << cnt-1 << '\n';
                    i = (int)tmp.back();
                    tmp.pop_back();
                    //std::cout << "tmp.size():" << tmp.size() << '\n';
                    //std::cout << "i:" << i+1 << '\n';
                    j = 0;
                    nexti = Adj[i][j]-1;
                }
                else{//残っていないなら
                    st[i].comp = cnt;
                    cnt++;      //たぶんこれで終わる
                    //std::cout << "cnt:" << cnt-1 << '\n';
                    if(cnt != n*2){//まだ未探索ノードが残ってる
                        i = 0;
                        while(st[i].flag){
                            i++;
                        }
                        newflag = true;
                    }
                    break;
                }
            }
            else{
                nexti = Adj[i][j]-1;
            }
        }
        if(!newflag){
            tmp.push_back(i);
            i = nexti;
        }
    }
}


int main(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int> > Adj;
    Adj.resize(n);
    input_graph(Adj, n);
    DFS(Adj, n);
    result(n);
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	cin>>n;
	vector<vector<int> > A(n);//????????????????????????-1?????\???????????????
	//??\???
	REP(i,n){
		int u,k;
		cin>>u>>k;
		A[i]=vector<int>(k,0);
		REP(j,k){
			int l;
			cin>>l;
			A[i][j] = l-1;
		}
	}
	//??¢?´¢
	vector<int> s;//??????????????????????????\???
	vector<int> dis(n,0);//??????????????????????????????
	vector<int> fin(n,0);//???????????????????????????
	int time=0;
	while(find(dis.begin(),dis.end(), 0) != dis.end()){
		int saisyo = find(dis.begin(),dis.end(), 0) -  dis.begin();
		//cout<<saisyo<<endl;
		s.push_back(saisyo);//?????????0???????????????
		while(!s.empty()){
		//REP(ss,3){
			int k = s.back();//??????????????????????????????
			if(dis[k]==0){
				time++;
				dis[k]=time;
				//cout<<"dis "<<k<<" / time "<<time<<endl;
			}
			bool isfinish=true;
			for(int i: A[k]){
				//cout<<"?????????"<<i<<endl;
				bool nai = find(s.begin(),s.end(), i) == s.end();
				if(fin[i]==0 && i!=k && nai){
					s.push_back(i);
					isfinish=false;
					break;
				}
			}
			if(isfinish){
				time++;
				fin[k]=time;
				s.pop_back();
				//cout<<"fin "<<k<<" / time "<<time<<endl;
			}
		}
	}
	REP(i,n){
		cout<<i+1<<" "<<dis[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;
typedef long long ll;

const int MAX = 100;

static int u[MAX][MAX];
static int d[MAX];
static int f[MAX];
static int v[MAX];


void seekNode(int n, int& elp) {

	d[n] = elp;
	elp++;
	v[n] = 1;

	for (int i = 0;i < MAX;i++) {
		if (u[n][i] > 0 && v[i] == 0) {
			seekNode(i, elp);
		}
	}


	f[n] = elp;
	elp++;
	return;
}


int main() {

	int n, uid, ap, tmp, elp;
	cin >> n;


	for (int i = 0;i < n;i++) {
		cin >> uid >> ap;
		for (int k = 0;k < ap;k++) {
			cin >> tmp;
			u[uid - 1][tmp - 1] = 1;
		}
	}
	elp = 1;
	for (int i = 0;i < n;i++) {
		if (v[i] == 0)	seekNode(i, elp);
	}

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


	return 0;
}