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 <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> d(101, -1), f(101, -1);
vector<vector<int> > c;

int n, u, k, v;
int dfs(int node, int time) {
    d[node] = time;
    for(int i=0; i<n; ++i) {
        if(c[node][i]==1&&d[i]==-1) time = dfs(i, time+1);
    }
    time++;
    f[node] = time;
    return time;
}

int main() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        vector<int> tmp(100, 0);
        for(int j=0; j<k; ++j) {
            cin >> v;
            tmp[v-1] = 1;
        }
        c.push_back(tmp);
    }

    bool isFinished = false;
    int node = 0;
    int time = 1;
    while(isFinished==false) {
        time = dfs(node, time);
        isFinished = true;
        for(node=0; node<n; node++) {
            if(d[node]==-1) {
                isFinished=false;
                break;
            }
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

set<int> to[101];
vector<int> from[101];
vector<int> d(101);
vector<int> f(101);

int dfs(int n, int t){
    if(d[n] != -1) return t-1;
    d[n] = t;
    for(auto it = to[n].begin(); it != to[n].end(); it++){
        t = dfs((*it),t+1);
    }
    t++;
    f[n] = t;
    return t;
}

int main(){
    int n;
    cin >> 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;
            to[u].insert(v);
            from[v].push_back(u);
        }
        d[u] = -1;
        f[u] = -1;
    }
    
    int t = dfs(1,1);
    for(int i = 1; i <= n; i++){
        if(d[i] == -1){
            t = dfs(i,t+1);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rp(i,j) for(long long i=0;i<j;i++)
#define rep(i,j,k) for(long long i=j;i<k;i++)
#define mod 1000000007
#define NIL -1
#define white 0
#define gray 1
#define black 2
typedef long long ll;
int n,tt=0,d[100],f[100];
int a[100][100]={0};
int nt[100]={1};
int color[100]={0};
void dfs_visit(int u){
    color[u]=gray;
    d[u]=++tt;
    rp(v,n){
        if(a[u][v]==0)continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    f[u]=++tt;
}
void dfs(){
    rp(u,n){
        if(color[u]==white)dfs_visit(u);
    }
    rp(u,n){
        cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl; 
    }
}
int main(){
    int u,k,v;
    cin>>n;
    rp(i,n){
        cin>>u>>k;
        u--;
        rp(j,k){
            cin>>v;
            v--;
            a[u][v]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
bool g[110][110];
int d[110];
int f[110];

void dfs(int s)
{
	stack<int> stk;
	d[s] = 0;
	stk.push(s);
	int current = 0;
	while (!stk.empty()) {
		int u = stk.top();
		int flag = 0;
		for (int j = 1; j <= n; j++) {
			if (g[u][j] && d[j] == -1) {
				flag = 1;
				stk.push(j);
				d[j] = ++current;
				break;
			}
		}

		if (flag == 0) {
			f[u] = ++current;
			stk.pop();
		}

	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			g[u][v] = true;
		}
	}

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

	dfs(1);

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

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include<stack>
#include <algorithm>
using namespace std;
#define max 101
#define WHITE 0
#define BLACK 1
#define GRAY -1
int color[max],d[max],f[max];
int t,varry[max][max];
stack<int> s;
int next(int u){
  int nv=-1;
  for(int i=0;i<varry[u][0];i++){
    if(color[varry[u][i+1]]==WHITE){
      nv=varry[u][i+1];
      break;
    }
  }
  
  return nv;
}
void visit(int r){
  int u,v;
  s.push(r);
  d[r]=++t;
  while(!s.empty()){
    u=s.top();
    v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
	s.push(v);
	color[v]=GRAY;
	d[v]=++t;
      }
    }
    else{
      s.pop();
      color[u]=BLACK;
      f[u]=++t;
      
    }
  }
}
void dfs(int u){
  for(int i=1;i<=u;i++)
    if(color[i]==WHITE)visit(i);
}
int main(){
  int n,u;
  cin>>n;
  for(int k=0;k<n;k++){
    cin>>u;
    cin>>varry[u][0];
    for(int i=0;i<varry[u][0];i++)
      cin>>varry[u][i+1];

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


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

void dfs(vector<vector<int>> g, bool seen[], int start, int d[], int f[], int &first)
{
    seen[start] = true;
    d[start] = first++;
    for (auto v : g[start])
    {
        if (seen[v])
        {
            continue;
        }
        dfs(g, seen, v, d, f, first);
    }
    f[start] = first++;
}

int main()
{
    int n;
    int first = 1;
    int last = 1;
    cin >> n;
    int d[n + 1], f[n + 1];
    bool seen[n + 1];
    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; i++)
    {
        seen[i] = false;
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!seen[i])
        {
            dfs(g, seen, i, d, f, first);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}