Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<iostream>
using namespace std;
typedef struct{
  int A[1000];
  int begin;
  int end;
}node;
node T[105];
int times=0;
  int n;
void function(int num){
  if(T[num].begin==0){
  times++;
    T[num].begin=times;
  }
  for(int j=1;j<=n;j++){
    if(T[num].A[j]==1){
      T[num].A[j]=0;
      function(j);
    }
  }
  if(T[num].end==0){
    times++;
    T[num].end=times;
  }
}
int main(){
  int num;
  int son;
  int z;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num;
    cin>>son;
    for(int j=0;j<son;j++){
      cin>>z;
      T[num].A[z]=1;
      }
  }
  for(int i=1;i<=n;i++){
    function(i);
  }
  for(int i=1;i<=n;i++){
      cout<<i<<" "<<T[i].begin<<" "<<T[i].end<<endl;
  }


  return 0;
}

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

vector<int> d, f;
int g[111][111];
int n;
int cnt;

void dfs(int now){
  bool flag = false;
  if(d[now] != 0) flag = true;
  else{
    cnt++;
    d[now] = cnt;
  }
  for(int i = 1; i <= n; i++){
    if(g[now-1][i-1] == 1 && d[i] == 0){
      dfs(i);
    }
  }
  cnt++;
  if(flag) cnt--;
  if(f[now] == 0) f[now] = cnt;
}

int main(){

  memset(g,0,sizeof(g));
  d.resize(111);
  f.resize(111);
  cin >> n;

  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    for(int i = 0; i < b; i++){
      int c;
      cin >> c;
      g[a-1][c-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<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
    int v;
    color[u]=GRAY;
    d[u]=++tt;
    for(v=0;v<n;v++)
    {
        if(M[u][v]==0)continue;
        if(color[v]==WHITE)
        dfs_visit(v);
    }
    color[u]=BLACK;
    f[u]=++tt;
}
void dfs()
{
    int u;
    for(u=0;u<n;u++) color[u]=WHITE;
    tt=0;
    for(u=0;u<n;u++)
    {
        if(color[u]==WHITE) dfs_visit(u);
    }
    for(u=0;u<n;u++)
    {
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}
int main()
{
    int a,b,c;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        a--;
        for(int i=0;i<b;i++)
        {
            scanf("%d",&c);
            c--;
            M[a][c]++;
        }
    }
    dfs();
    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

ll d[100], f[100], now, cnt;
char flag[100];
vector<int> vec[100];

int dfs(int n) {
  if(flag[n]) return 0;
  flag[n] = 1;
  cnt++;
  d[n] = cnt;
  vector<int>::iterator it;
  for(it = vec[n].begin(); it != vec[n].end(); ++it) {
    if(!flag[*it]) dfs(*it);
  }
  ++cnt;
  f[n] = cnt;
  return 0;
}

int main(void) {
  ll n;
  scanf("%d", &n);
  now = 0, cnt = 0;
  rep(i, n) flag[i] = 0;
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
    sort(vec[u].begin(), vec[u].end());
  }
  now = 0;
  while( 1 ) {
    dfs(now);
    int s = 1, i;
    for(i = 0; i < n; ++i) if(!flag[i]){
      s = 0;
      break;
    }
    if(s) break;
    else now = i;
    //rep(j, n) printf("%d ", (int)flag[j]);
    printf("%d\n", i);
    //return 0;
  }
  rep(i, n) printf("%d %lld %lld\n", i + 1, d[i], f[i]);
  return 0;
}

C++: //
//  main.cpp
//  DFS
//
//  Created by 2594345669 on 2016/12/05.
//  Copyright ?? 2016??´ as. All rights reserved.
//

#include <iostream>
using namespace std;

typedef pair<int, int> edge;

int vernum[101];
edge path[101][101];
int n;

edge found[101];

int t=1;
void dfs(int v){
    found[v].first = t;
    int i=0;
    while(1){
        if(!path[v][i].first)
            break;
        if(!found[path[v][i].second].first){
            t++;
            dfs(path[v][i].second);
            t++;
        }
        i++;
    }
    found[v].second = t+1;
}

int main() {
    int i, j;
    ios_base::sync_with_stdio(0);
    
    int e, v;
    cin >> n;
    
    for(i=1; i<=n; i++){
        cin >> vernum[i];
        cin >> e;
        for(j=0; j<e; j++){
            cin >> v;
            path[i][j] = make_pair(i, v);
        }
    }
    
    for(i=1; i<=n; i++){
        if(!found[i].first)
            dfs(i);
    }
    
    for(i=1; i<=n; i++){
        cout << vernum[i] << " " << found[i].first << " " << found[i].second << endl;
    }
    
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int n,i,j,x,y,nx;
int map[100][100]={0};
int color[100]={0};//0 null  1 gray 2 black 
int start[100]={0};
int end[100]={0};
int pretime=0;
int dfs(int p){
	for(int m=0;m<n;m++){
		if(map[p][m]==1&&color[m]==0){
			start[m]=++pretime;
			color[m]=1;
			dfs(m);
		}
	}
	end[p]=++pretime;
	color[p]=2;
	return 0;
}
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>nx;
		for(j=0;j<nx;j++){
			cin>>y;
			map[x-1][y-1]=1;
		}
	}
	for(i=0;i<n;i++){
		if(color[i]==0){
			color[i]=1;
		    start[i]=++pretime;
	     	dfs(i);
		}

	}

	for(i=0;i<n;i++){
		cout<<i+1<<" "<<start[i]<<" "<<end[i]<<endl;
	}
	
	
	return 0;
}