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 <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int MAX_N = 100;

int N;
vi G[MAX_N];
int d[MAX_N];
int f[MAX_N];

void dfs(int v=0)
{
    static int t=1;
    d[v] = t++;
    for(auto u:G[v]){
        if (d[u]>0) continue;
        dfs(u);
    }
    f[v] = t++;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    rep(i,N){
        int u,k; cin>>u>>k; u--;
        rep(i,k){
            int v; cin>>v; v--;
            G[u].pb(v);
        }
    }
    rep(i,N)if(d[i]==0){
        dfs(i);
    }
    rep(i,N){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
    }
    return 0;
}

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

vector<int> G[102];
int d[102];
int f[102];
bool used[102];


int dfs(int i, int t){
    d[i] = t++;
    used[i] = true;
    for(vector<int>::iterator it = G[i].begin(); it != G[i].end(); ++it){
        if(!used[*it]){
            t = dfs(*it, t);
        }
    }
    
    f[i] = t++;
    return t;
}

int main()
{
    int n,u,k,v;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
            cin >> v;
            G[u].push_back(v);
        }
    }
    
    dfs(1,1);
    
    for(int i = 1; i <= n; ++i){
        cout << i << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

C++: #include <iostream>
using namespace std;
int g[101][102],ch[101][2]={0},kh;

int dfs(int k,int n){
  ch[n][0]=k;
  //cout<<k<<n<<"<--"<<endl;/////////
  for(int i=1;i<=g[n][0];i++){
    if(ch[g[n][i]][0]==0){
      k=dfs(k+1,g[n][i]);
    }
  }
  ch[n][1]=k+1;
  kh=k+1;
  return k+1;
}

int main(){
  int a,b,c,d;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b>>c;
    g[b][0]=c;
    for(int j=1;j<=c;j++){
      cin>>d;
      g[b][j]=d;
    }
  }
  dfs(1,1);
  for(int i=1;i<=a;i++)if(ch[i][0]==0)dfs(i,kh+1);
  for(int i=1;i<=a;i++){
    cout<<i<<" "<<ch[i][0]<<" "<<ch[i][1]<<endl;
    
  }
  return 0;
}

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

int n;
int v[100][100];
int color[100], d[100], f[100], tt;
/*
  color: ???????????¶???
    0: ???????¨??????????????????????;
    1: ?¨??????????????????????;
    2: ???????????????;
  d: ?????????????????????;
  f: ?????????????????????;
  tt: ?¨??????????;
*/


int dfs(int u)
{
  color[u] = 1;
  d[u] = ++tt; //????????????????¨????
  for (int i = 0; i < n; i++) {
    if (v[u][i] == 0) continue;
    if (color[i] == 0) {
      dfs(i);
    }
  }
  color[u] = 2;
  f[u] = ++tt; //?¨?????????????
}

signed main()
{
  int u, k;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      v[u][tmp] = 1;
    }

  }

  for (int u = 0; u < n; u++) {
    if (color[u] == 0) dfs(u);
  }

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

  return (0);
}

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

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
  for (int v = nt[u]; v < n; v++) {
    nt[u] = v + 1;
    if (M[u][v]) {
      return v;
    }
  }
  return -1;
}

void dfs_visit(int r) {
  for (int i = 0; i < n; i++) {
    nt[i] = 0;
  }

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while(!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) {
      dfs_visit(u);
    }
  }

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

int main() {

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

  int u, k, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; // to 0 origin
    for (int j = 0; j < n; j++) {
      cin >> v;
      v--; // to 0 origin
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

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

enum Status {WHITE, GRAY, BLACK};

stack<int> stc;
Status *status;
int *discovered, *finished;
vector<vector<int> > a;
int n, timer;

void dfs(int i){
        if(status[i]==BLACK) return;
        if(status[i]==WHITE){
                discovered[i] = ++timer;
                status[i] = GRAY;
        }
        stc.push(i);

        for(int j=0;j<a[i].size();j++) dfs(a[i][j]);

        if(status[i]==GRAY){
                finished[i] = ++timer;
                status[i] = BLACK;
        }
        stc.pop();
}

int main(){

        cin>>n;
        a = vector<vector<int> >(n, vector<int>());
        status = new Status[n];
        discovered = new int[n];
        finished = new int[n];

        int m, k, r;
        for(int i=0;i<n;i++){
                cin>>r;
                cin>>m;
                for(int j=0;j<m;j++){
                        cin>>k;
                        a[r-1].emplace_back(k-1);
                }
        }
        for(int i=0;i<n;i++) status[i] = WHITE;

        timer = 0;
        dfs(0);


        for(int i=0;i<n;i++){
                cout<<i+1<<" "<<discovered[i]<<" "<<finished[i]<<endl;
        }
        return 0;
}