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<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

vector<int> d(100, 1), f(100);

int dfs(vector<vector<int>> a, int s) {
	int n = a.size();
	int res = 0;
	REP(j, n) {
		if (d[j] == 1 && a[s][j]) {
			if (res == 0) {
				d[j] = d[s] + 1;
			}
			else {
				d[j] = res;
			}
			res = dfs(a, j) + 1;
		}
	}
	if (res == 0) return f[s] = d[s] + 1;
	return f[s] = res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n, 0));
	REP(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		REP(j, k) {
			int v;
			cin >> v;
			a[u][--v] = 1;
		}
	}
	dfs(a, 0);
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
	}
	
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++)
const int INF = 1001001001;
int n, u, k;
int D[100],F[100];
vector<int> edges[100];
int tim = 0;

void dfs(int cur) {
	if (D[cur] == INF) {
		tim += 1;
		D[cur] = tim;//タイムスタンプ押印
	}	
	for (int dst = 0; dst < n; dst++) {
		vector<int>::iterator result = find(edges[cur].begin(), edges[cur].end(), dst);
		if (result != edges[cur].end() && D[dst] == INF) dfs(dst);
	}
	tim += 1;
	F[cur] = tim;
		 //タイムスタンプ押印		
}

int main() {
	cin >> n; //n頂点


	for (int i = 0; i < n; i++)//iは頂点
	{
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			int l;
			cin >> l;
			edges[u - 1].push_back(l - 1);
		}//入力終わり
		D[i] = INF;
		F[i] = INF;		
	}
	for (int p = 0; p < n; p++) {
		if(D[p]==INF)dfs(p);//未訪問ならばッてこと
	}
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << D[i] <<" "<<F[i]<< endl;		
	}
	return 0;
}

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

typedef struct {
	bool endflag;
	int firsttime;
	int endtime;
}State;

const int Max = 100;
int map[Max + 1][Max + 1] = { 0 };
std::stack<int> st;
std::vector<State> state;


int main()
{
	int n, k, v, x;
	int cnt = 1;

	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		std::cin >> x >> k;
		for (int j = 1; j <= k; j++) {
			std::cin >> v;
			map[x][v] = 1;
		}
	}

	State s = { false,0,0 };
	for (int i = 0; i <= n; i++) {
		state.push_back(s);
	}

	while (1) {
		if (st.empty() == true) {
			if (state[1].endflag == true) {
				break;
			}
			else {
				st.push(1);
				state[1].firsttime = cnt;
				cnt++;
				continue;
			}
		}

		bool flag = false;
		for (int i = 1; i <= n; i++) {
			if (map[st.top()][i] == 1) {
				if (state[i].endflag == false) {
					st.push(i);
					state[i].firsttime = cnt;
					cnt++;
					flag = true;
					break;
				}
			}
		}
		if (flag == true) {
			continue;
		}
		else {
			state[st.top()].endflag = true;
			state[st.top()].endtime = cnt;
			cnt++;
			st.pop();
		}
	}

	for (int i = 1; i <= n; i++) {
		std::cout << i << " " << state[i].firsttime << " " << state[i].endtime << std::endl;
	}

	return 0;
}

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

int n;
int t = 0; //time
int d[110] = {}; //discover
int f[110]; //finish
bool a[110][110] = {}; //adjacency matrix

void dfs(int u){
  d[u] = ++t; //record the discovering time

  //if be adjoining and have not been discovered, search
  for(int i = 1;i <= n;i++) if(a[u][i] && d[i] == 0) dfs(i);
  
  f[u] = ++t; //record the finishing time
}

int main(){
  
  int u, k, v;

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

  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      //if be adjoining and have not been discovered, search
      if(a[i][j] && d[i] == 0) dfs(i);
    }
  }

  //output
  for(int i = 1;i <= n;i++) cout << i << " " << d[i] << " " << f[i] << endl;
  
  return 0;
}

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

class Graph {
protected:
	vector< vector<int> > adjl;
public:
	Graph(int n) : adjl(n){}
	void PushAdjl(int pl, int val) { adjl[pl].push_back(val); }
};

class DFGraph : public Graph {
private:
	int t;
	vector<int> d, f;
public:
	DFGraph(int n) : Graph(n), d(n), f(n) {}
	void DepthFirstSearch(int);
	void DFSSub(int);
	void Showdf();
};

void DFGraph::DepthFirstSearch(int begin = 0) {
	t = 1;
	DFSSub(begin);
	for (int i = 0; i < d.size(); i++)
		if (d[i] == 0)
			DFSSub(i);
}

void DFGraph::DFSSub(int v) {
	d[v] = t;
	t++;
	for (auto&& i : adjl[v])
		if (d[i] == 0)
			DFSSub(i);
	f[v] = t;
	t++;
}

void DFGraph::Showdf() {
	for (int i = 0; i < d.size(); i++)
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

int main() {
	int n;
	cin >> n;
	DFGraph dfg(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			dfg.PushAdjl(u - 1, t - 1);
		}
	}
	dfg.DepthFirstSearch();
	dfg.Showdf();
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  
  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;
    }
  }

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      t=1;
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include <iostream>
#include<stack>
#include<vector>
using namespace std;
int main(void){
    int n ,i,DP[1001][1001],num,p,k,f[101][3],ptr=1,v;
    stack<int> s;
        cin>>n;
    for(i=1;i<=n;i++){
        cin>>p>>k;
        for(int j=1;j<=k;j++){
            cin>> num;
            DP[i][num]=1;
        }
    }
    for(i=1;i<=n;i++){
        DP[0][i]=1;
    }
    s.push(0);
    while(!s.empty()){
        v=s.top();
        for(int i=1;i<=n;i++){
            if(DP[v][i]==1&&f[i][0]==0){
                    s.push(i);
                    f[i][0]=1;
                    f[i][1]=ptr;
                    goto Exit;
            }
        }
        s.pop();
        f[v][2]=ptr;
        Exit:;
        ptr++;
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<f[i+1][1]<<" "<<f[i+1][2]<<endl;
    }
}