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 <string>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
#define MAX 100000

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(){
  int u,k,v;
  cin >> n;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=0;
    }
  }

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

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

struct Node{
	int color, d, f;
	queue<int> Q;
};

int main(){
	int n;
	cin >> n;
	Node node[n + 1];
	stack<int> move;
	for(int i = 1; i <= n; i++){
		int u, k, v;
		cin >> u >> k;
		node[u].color = WHITE;
		while(k--){
			cin >> v;
			node[u].Q.push(v);
		}
	}

	move.push(1);
	int tt = 1, p, next;
	node[1].color = GRAY;
	node[1].d = tt;
	tt++;

	while(!move.empty()){
		p = move.top();
		if(node[p].Q.empty()){
			node[p].color = BLACK;
			node[p].f = tt;
			move.pop();
			tt++;
		} else {
			next = node[p].Q.front();
			if(node[next].color == WHITE){
				move.push(next);
				node[next].color == GRAY;
				node[next].d = tt;
				tt++;
			} else {
				node[p].Q.pop();
			}
		}
	}

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

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
 
int find_t[101],end_t[101];
vector<queue<int> > vec(101);
int flag[101];
int t=1;
 
void DFS(int);
void Print();
 
int main(int argc,char* argv[]){
  int n,id,cnt,x;
   
  memset(find_t,255,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(flag,0,sizeof(flag));
 
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    flag[id]=0;
    queue<int> tmp;
    for(int l=0;l<cnt;l++){
      cin>>x;
      tmp.push(x);
    }
    vec[id]=tmp;
  }
   
  for(int i=1;i<=n;i++){
    if(flag[i]==0)
      DFS(i);
  }
  Print();
   
  return 0;
}
 
void DFS(int p){
  if(flag[p]==0){
    find_t[p]=t++;
    flag[p]=1;
  }
  else
    return;
     
  queue<int> tmp=vec[p];
  while(!tmp.empty()){
    DFS(tmp.front());
    tmp.pop();
  }
 
  end_t[p]=t++;
}
 
void Print(){
  for(int i=1;i<=100;i++){
    if(find_t[i]!=-1)
      printf("%d %d %d\n",i,find_t[i],end_t[i]);
  }
}

C++: #include<iostream>
#include<cstdio>
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n, M[101][101];
int color[101], count1[101], count2[101], t;

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	t++;
	count1[u] = t;
	for (v = 1; v <= n; v++) {
		if (M[u][v] == 0) {
			continue;
		}

		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	t++;
	count2[u] = t;
}

void dfs() {
	int u;
	for (u = 1; u <= n; u++) {
		color[u] = WHITE;
		t = 0;
	}
	for (u = 1; u <= n; u++) {
		if (color[u] == WHITE) {
			dfs_visit(u);
		}
	}
	for (u = 1; u <= n; u++) {
		printf("%d %d %d\n", u, count1[u], count2[u]);
	}
}

int main() {
	int u, v, k, i, j;
	cin >> n;

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

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

	dfs();

	return 0;
}

/*
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
*/

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

const int MAX_N = 100;
vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
bool used[MAX_N];

int stamp;

void dfs(const int v) {
    d[v] = stamp++;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i];
        if(used[u] == false) dfs(u);
    }
    f[v] = stamp++;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k; u--;
        while(k--) {
            int v; cin >> v; v--;
            G[u].push_back(v);
        }
        sort(G[u].begin(), G[u].end());
    }

    fill(used, used + N, false);
    stamp = 1;
    dfs(0);

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

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct Node {
	int k, d, f;
	vector<int> v;
};

#define MAX_N 100

Node node[MAX_N + 1];
int _d, _f;

void dfs(int u) {
	if (node[u].d == 0) node[u].d = _d++;
	for (int i = 0; i < node[u].k; ++i)
		dfs(node[u].v[i]);
	if (node[u].f == 0) node[u].f = _f++;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u;
		cin >> u;
		cin >> node[u].k;
		for (int j = 0; j < node[u].k; ++j) {
			int v;
			cin >> v;
			node[u].v.push_back(v);
		}
		node[u].d = node[u].f = 0;
	}
	_d = 1;
	_f = n + 1;
	dfs(1);
	for (int i = 1; i <= n; ++i)
		cout << i << " " << node[i].d << " " << node[i].f << endl;
	return 0;
}

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

struct Node{
  vector<int> AJ;
  bool visit;
  int d, f;
};

Node G[101];
int t = 0;

void dfs(int idx){
  G[idx].visit = true;
  G[idx].d = ++t;
  for(int i = 0; i < G[idx].AJ.size(); i++){
    if(!G[G[idx].AJ[i]].visit) dfs(G[idx].AJ[i]);
  }
  G[idx].f = ++t;
}

int main(){
  int n, u, k, v;
  cin >> n;
  for(int i = 0 ; i < 101; i++) G[i].visit = false;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      G[u].AJ.push_back(v);
    }
  }
  for(int i = 1; i <= n; i++) if(!G[i].visit) dfs(i);
  for(int i = 1; i <= n; i++) cout << i << " " << G[i].d << " " << G[i].f << endl;
  return 0;
}