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

C++: #include <iostream>
#include <stack>
#include <cstdio>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
stack<int> S;
int n;
int t=0;

int next(int u){
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1&&color[i]==WHITE) return i;
  }
  return NIL;
}

void dfs(int u){
  S.push(u);
  color[u]=GRAY;
  d[u]=++t;
  while(S.empty()==false){
    u=S.top();
    int v=next(u);
    if(v!=NIL){
      color[v]=GRAY;
      d[v]=++t;
      S.push(v);
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  dfs(1);
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)

int d[105], f[105];
bool seen[105];

void dfs(vector<vector<int> > &G, int n, int &x){
    if(seen[n]) return;
    x++;
    d[n] = x;
    seen[n] = true;

    rep(i, G[n].size()){
        int p = G[n][i];
        if(seen[p]) continue;
        dfs(G, p, x);
    }

    x++;
    f[n] = x;
}

int main(){
    int n;
    cin >> n;

    vector<vector<int> > G(n);
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            v--;
            G[i].push_back(v);
        }
    }

    rep(i, n){
        seen[i] = false;
    }
    int x = 0;
    rep(i, n){
        dfs(G, i, x);
    }

    rep(i, n){
        cout << i+1 << " " <<  d[i] << " " << f[i] << "\n";
    }


    return 0;
}

C++: #include<cstdio>
const char N_MAX = 105;
short time=0;
bool matrix[N_MAX][N_MAX];
char n;
struct Node{
    char state;//0:undiscovered 1:active 2:end
    short stTime, endTime;
};
Node V[N_MAX];
char next(char num){
    for(char i=0;i<n;i++){
        if(matrix[num][i]&&V[i].state==0){
            return i;
        }
    }
    return -1;
}
void dfs(char num){
    if(num==-1) return;
    V[num].stTime = ++time;
    V[num].state = 1;
    for(char i=next(num); i!=-1;i=next(num)){
        dfs(i);
    }
    V[num].state = 2;
    V[num].endTime = ++time;
}
void buildMatrix(){
	for(char i=0; i<n;i++){
		int degree, index;
		scanf("%u%u", &index, &degree);
		for(char j=0; j<degree; j++){
			int temp;
			scanf("%d", &temp);
			matrix[index-1][temp-1] = true;
		}
	}
}
int main(){
    scanf("%d", &n);
    buildMatrix();
    for(char i=0; i<N_MAX; i++){
        if(V[i].state==0){
            dfs(i);
        }
    }
    for(char i=0;i<n;i++){
        printf("%d %d %d\n", i+1, V[i].stTime, V[i].endTime);
    }
    return 0;
}

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

using namespace std;

struct Edge
{
	int to;
};

vector<vector<int>> DFS(vector<vector<Edge>>& G)
{
	int timecounter = 0;
	vector<vector<int>> result;
	result = vector<vector<int>>(2, vector<int>(G.size(), 0));
	vector<int> prev(G.size(),0);
	
	for(int i = 0; i < G.size(); i++){
		int next = i + 1;
		while(result[1][i] == 0){
			int tmp;
			if(result[0][next - 1] == 0){
				timecounter += 1;	
				result[0][next - 1] = timecounter;
			}

			if(G[next - 1].empty()){
				if(result[1][next - 1] == 0){
					timecounter += 1;
					result[1][next - 1] = timecounter;
				}
				next = prev[next - 1];
			}else{
				tmp = G[next - 1].begin()->to;
				G[next - 1].erase(G[next - 1].begin());
				prev[tmp - 1] = next;
				next = tmp;
			}
		}
	}
	return result;
}

int main(void)
{
	int n;
	cin >> n;

	vector<vector<Edge>> AdjList(n);
	for(int i = 0; i < n; i++){
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			AdjList[i].push_back(Edge{v});
		}
	}

	vector<vector<int>> timestump = DFS(AdjList);
	
	for(int i = 0; i < AdjList.size(); i++){
		cout << i + 1 << " " << timestump[0][i] << " " << timestump[1][i] << endl;
	}
	return 0;
}