Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

int n, dd[101], f[101], tmap[101][101];
int color[101], t = 1;
stack<int> S;

int a(){
	int d = S.top();
	dd[d] = t;
	t++;
	color[d] = 1;
	for (int i = 1; i <= n; i++){
		if (color[i] == 0 && tmap[d][i] == 1){
			S.push(i);
			a();
		}
	}
	
	f[d] = t;
	t++;
	return 0;
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		dd[i] = f[i] = color[i] = 0;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++){
		if (color[i] == 0){
			S.push(i);
			a();
		}
	}
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << " " << f[i] << endl;
	}
	return 0;
}

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();
}