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 <stack>
#include <vector>

using namespace std;

int n;
int V[105][105];
vector<int> d(105, 0), f(105, 0);
int t = 0;

void dfs(int x) {
	bool p = false;
	if (d[x] != 0) p = true;
	if (d[x] == 0) {
		t++;
		d[x] = t;
	}
	for (int j = 1; j <= n; j++) {
		if (V[x - 1][j - 1] == 1 && d[j] == 0) {
			dfs(j);
		}
	}
	t++;
	if (p) t--;
	if (f[x] == 0) f[x] = t;
}


int main() {
	cin >> n;
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			V[i][j] = 0;
		}
	}
	for (int i = 0; i<n; i++) {
		int p, m;
		cin >> p >> m;
		for (int j = 0; j<m; j++) {
			int q;
			cin >> q;
			V[p - 1][q - 1] = 1;
		}
	}
	for (int i = 0; i<n; i++) {
		dfs(i + 1);
	}
	for (int i = 0; i<n; i++) {
		cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef int ll;
typedef pair<ll, ll> P;

ll N = 100;
vector<ll> ans1;
vector<ll> ans2;
vector<bool> seen;
ll C = 0;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}


void dfs(vector< vector<ll> > &G, int v) {
  seen[v] = true;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    ans1[next_v] = ++C;
    //printf("ans1[%d] = %d\n", next_v+1, C);
    dfs(G, next_v); // 再帰的に探索
    ans2[next_v] = ++C;
    //printf("ans2[%d] = %d\n", next_v+1, C);
  }
}

int main() {
  cin >> N;
  vector< vector<ll> > G(N);
  G.resize(N);
  seen.resize(N, false);
  ans1.resize(N, 0);
  ans2.resize(N, 0);
  int k;
  int tmp;
  rep(i, N) {
    cin >> tmp >> k;
    rep(j, k) {
      int tmp;
      cin >> tmp;
      G[i].push_back(tmp-1);
    }
  }

  rep(i, N) {
    if (!seen[i]) {
      ans1[i] = ++C;
      dfs(G, i);
      ans2[i] = ++C;
    }
  }
  rep(i, N) {
    cout << i+1 << " " << ans1[i] << " " << ans2[i] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
struct Node{
  int u;
  int k;
  int v[99];

  int start;
  int finish;
};

int deep(Node nod[],int x,int count){
  if(nod[x].start)
    return count;

  nod[x].start=(++count);
  for(int i=0; i<nod[x].k; i++)
    count = deep(nod,nod[x].v[i]-1,count);

  nod[x].finish= (++count);
  return count;
}

int main(){
  int n,count=0;
  Node nod[100];

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> nod[i].u >> nod[i].k;
    
    for(int j=0; j<nod[i].k; j++)
      cin >> nod[i].v[j];
    
    nod[i].start=0;
    nod[i].finish=0;
  }

  for(int i=0; i<n; i++)
    count = deep(nod,i,count);
  
  for(int i=0; i<n; i++){
    cout << nod[i].u << " " << nod[i].start << " " << nod[i].finish << endl;
  }
}

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

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x,head=0;
  
  memset(find_t,0,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    for(int l=0;l<cnt;l++){
      cin>>x;
      flag[x]=1;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }

  for(int i=1;i<=n;i++){
    if(flag[i]==0){
      head=i;
      break;
    }
  }

  memset(flag,0,sizeof(flag));
  DFS(head);
  Print();
  
  return 0;
}

void DFS(int p){
  if(flag[p]==0){
    find_t[p]=t++;
    flag[p]=1;
  }
  else
    return;
    
  if(lft[p]!=-1)
    DFS(lft[p]);
  if(rht[p]!=-1)
    DFS(rht[p]);

  end_t[p]=t++;
}

void Print(){
  for(int i=1;i<=100;i++){
    if(find_t[i]!=0)
      printf("%d %d %d\n",i,find_t[i],end_t[i]);
  }
}

C++: #include<stdio.h>
#define MAX 102
#define WHITE 0
#define BLACK 1
#define GRAY 2


void init();
void visit(int);

int col[MAX];
int n, t = 0;
int d[MAX],f[MAX],edge[MAX],num[MAX][MAX],G[MAX][MAX];

void init(){

  int i,j;

  for(i = 0; i <= n; i++){
      col[i] = WHITE;
    }

}

void dFSearch(){
  int i;
  for(i = 1; i <= n; i++){
    if(col[i] == WHITE) visit(i);
  }
}

void visit(int u){
  int i,j;

  col[u] = GRAY;
  t += 1;
  d[u] = t;

  for(j = 0; j < n; j++){
    if(G[u][j] == 10) {
      if(col[j+1] == WHITE ){
    visit(j+1);
      }
    }
  }

  col[u] = BLACK;
  t = t + 1;
  f[u] = t;

}


int main(){

  int i,j,k = 0,vertex,number;

  scanf("%d\n",&n);
  init();

  for(i = 1; i <= n; i++){
    scanf("%d %d",&vertex,&edge[i]);
    for(j = 1; j <= edge[i]; j++){
      scanf("%d",&number);
      G[vertex][number-1] = 10;
    }
    scanf("\n");
  }

 dFSearch();

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

  return 0;


}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};
int n;
int t = 0;
int d[N] = {0};
int f[N] = {0};

void dfs(int id) {
    ++t;
    // cerr << "begin: " <<  id << " " << t << endl;
    if (d[id] == 0)
        d[id] = t;

    for (int i = 0; i < n; ++i) {
        if (A[id][i] != 0) {
            dfs(i);
        }
    }

    // cerr << "end: " <<  id << " " << t << endl;
    ++t;
    f[id] = t;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

    dfs(0);

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

    return 0;
}

C++: #include <iostream>
using namespace std;
int cnt = 1;
void DepthFirstSearch(int now,int n,int a[][],int b[],int c[],int d[]){
  b[now]=1;
  c[now]=cnt;
  cnt++;
    for(int i=0;i<n;i++){
        if(a[now][i] && b[i]!=1){
            DepthFirstSearch(i,n,a,b,c,d);
            cnt++;
        }
    }
  d[now]=cnt;
}
int main(){
  int a[100][100],b[100],c[100],d[100]
  int n,u,m,num;
  cin>>n;
  for(int i = 0;i < n;i++){
    cin>>u>>m;
    for(int j = 0;j < m;j++){
      cin >> num;
      a[u-1][num-1]=1;
    }
  }
    for(int i=0;i<n;i++){
       if(b[i]!=1){
         DepthFirstSearch(i,n,a,b,c,d);
         cnt++;
       }
    }
  
    for(int i=0;i<n;i++){
        cout<< i+1 << " " << c[i] << " " << d[i]<<endl;
    }
  return 0;
  
}