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 <cstdio>
#include <vector>
using namespace std;

const int maxn = 100;
vector<int> G[maxn + 5];
//int book[maxn + 5][maxn + 5];
int n;
int d[maxn + 5];
int f[maxn + 5];
int time = 0;


void dfs(int vertex) {
    d[vertex] = ++time;

    int len = G[vertex].size();
    for(int i = 0; i < len; i++) {
        if(!d[G[vertex][i]]) dfs(G[vertex][i]);
    }

    f[vertex] = ++time;
}

int main() {
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int num;
        scanf("%d", &num);
        int count;
        scanf("%d", &count);


        while(count--) {
            int temp; scanf("%d", &temp);
            G[num].push_back(temp);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(!d[i]) dfs(i);
    }

    for(int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int d[110], f[110];
vector<int> g[110];
int t;
bool used[110];
void solve(int i) {
    if (used[i]) return;
    used[i] = true;
    t++;
    d[i] = t;
    for (int j: g[i]) {
        solve(j);
    }
    t++;
    f[i] = t;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, u;
        cin >> id >> u;
        for (int j = 0; j < u; j++) {
            int a;
            cin >> a;
            g[i].push_back(a-1);
        }
    }
    t = 0;
    fill_n(used, 110, false);
    for (int i = 0; i < n; i++) {
        solve(i);
    }
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

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

#define M 100
#define TRUE 10
#define WHITE 1
#define BLACK 2
#define GRAY 3
stack<int> T;
int n,t = 1,D[M + 1],F[M + 1],color[M + 1],N[M + 1][M + 1],Ni[M + 1];

int next(int v){
  for(int i = Ni[v];i <= n;i++){
    Ni[v] = i + 1;
    if(N[v][i] == TRUE) return i;
  }
  return -1;
}
  
void dsearch(int v){
  int top;
  
  T.push(v);
  color[v] = GRAY;
  D[v] = t++;

  while(!T.empty()){
    v = T.top();
    top = next(v);
    if(top != -1){
      if(color[top] == WHITE){
	color[top] = GRAY;
	D[top] = t++;
	T.push(top);
      }
    }
    else{
      T.pop();
      color[v] = BLACK;
      F[v] = t++;
    }
  }
}
  
int main (){
  int r,c,v;

  cin >> n;
  for(int i = 1;i <= n;i++){
    color[i] = WHITE;
    Ni[i] = 0;
  }
 
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      N[i][j] = 0;
    }
  }
  
  for(int i = 1;i <= n;i++){
    cin >> r >> c;
    for(int j = 1;j <= c;j++){
      cin >> v;
      N[r][v] = TRUE;
    }
  }
  for(int i = 1;i <= n;i++){
    if(color[i] == WHITE) dsearch(i);
  }
  for(int i = 1;i <= n;i++){
    cout << i << " "<< D[i] << " "<< F[i] << endl;
  }

  return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = tm++;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

C++: #include <cstdio>

int n, G[100][100], d[100], f[100], checked[100], time;

void dfs_visit(int u) {
    int i;
    checked[u] = 1;
    d[u] = ++time;
    for (i = 0; i < n; i++) {
        if (G[u][i] == 0) continue;
        if (checked[i] == 0) dfs_visit(i);
    }
    f[u] = ++time;
}

void dfs() {
    int i;
    for (i = 0; i < n; i++) checked[i] = 0;
    time = 0;

    for (i = 0; i < n; i++) {
        if (checked[i] == 0) dfs_visit(i);
    }
}

int main(void) {
    int u, k, v, i, j;
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) G[i][j] = 0;
    
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }

    dfs();

    for (i = 0; i < n; i++) {
        printf("%d %d %d\n", i + 1, d[i], f[i]);
    }

    return 0;
}

C++: #include <stdio.h>

int A[101][101];
int ans[101][3];
int an = 1;


int judge(int i, int j){
  if(ans[i][j] == 0){
    ans[i][j] = an;
    an++;
  }
}

int serch(int a[101][101], int  ni, int n){
  int  j;
  
  for(j=0; j<n; j++){
    if(A[ni][j] == 1){
      judge(j, 1);
      serch(A, j, n);
    }
  }
  judge(ni, 2);
}

int  main(){
  int i, j, k, n, x, y;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
      A[i][j] = 0;
    ans[i][0] = i+1;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d", &x, &y);
    for(j=0; j<y; j++){
      scanf("%d", &k);
      A[i][k-1] = 1;
    }
  }
  
  for(j=0; j<n; j++){
  judge(j,1);
    for(i=0; i<n; i++){
      if(A[0][i] == 1){
        judge(i, 1);
        serch(A, i, n);
      }
    }
    judge(j, 2);
  }
  
  for(i=0; i<n; i++){
    for(j=0; j<3; j++){
      if(j>0)
        printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}