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
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

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

using namespace std;

/*****************************************/
/*         Function prototype            */
/*****************************************/

vector<vector<int> > list_to_mat(vector<vector<int> >& adj);
void dump_mat( vector<vector<int> >& mat);
void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int *t);

/*****************************************/
/*            Main Function              */
/*****************************************/


int main(){
  int n; cin >> n;

  vector<vector<int> > list(n+1);
  for(int i=0; i<n; i++){
    int u,k; cin >> u >> k;
    vector<int> tmp(k);
    for(int j=0; j<k; j++) cin >> tmp[j];
    sort(tmp.begin(),tmp.end());
    list[u] = tmp;
  }
  int t=1;
  vector<int> d(n+1,-1);
  vector<int> f(n+1,-1);

  dfs(list,1,d,f,&t);

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



/*****************************************/
/*            Implimentation             */
/*****************************************/


void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(auto v : adj_list[now]){
    if(d[v] != -1) continue;
    dfs(adj_list, v, d, f, t);
  }
  f[now] = *t;
  (*t)++;
  return ;
}


vector<vector<int> > list_to_mat(vector<vector<int> >& adj){
  const int mat_size = (int)adj.size();
  vector<vector<int> > ans(mat_size,vector<int>(mat_size,0));
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<adj[i].size(); j++){
      ans[i][adj[i][j]-1] = 1;
    }
  }
  return ans;
}


void dump_mat( vector<vector<int> >& mat){
  
  const int mat_size = (int)mat.size();
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<mat[i].size(); j++){
      cout << mat[i][j];
      if(j!=mat[i].size()-1)
	cout << " ";
      else
	cout << "\n";
    }
  }
}

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 u, v, k, i, j;
	scanf("%d", &n);
	for (i = 0; i<n; i++)
		for (j = 0; j<n; j++)
			M[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--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u,k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200] = {false};
int fincou=1;
void dfs(int where,int find){
  fincou++;
 
  GetIt[where]=find;
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[where]){
	dfs(imap[where][i],find+1);
	fincou++;
	used[where] = true;
      }
    }
  }
    FinIt[where] = fincou;
    
}

int main(){
 
  int ad;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u;
    cin >> k[u];
    for(int j=0;j<k[u];j++){
      cin >> ad;
      arisutoteresu[u][ad] = 1;
      imap[u][j] = ad; 
    }
  }


  for(int j=0;j<n;j++)used[j] = false;
  dfs(1,1);

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

  return 0;
}

C++: #include <stdio.h>
int size[101],g[101][101],x[101], y[101], k, d;
void dfs(int z){
  int i;
  x[z] = d++;
  for(i=1;i<=size[z];i++) if(!x[g[z][i]]) dfs(g[z][i]);
  y[z] = d++;
}
 
main(){
  int i, j, a;
  d=1;
  scanf("%d", &k);
  for(i=1;i<=k;i++){
    x[i] = y[i] = 0;
    scanf("%d", &a);
    scanf("%d", &size[a]);
    for(j=1;j<=size[a];j++) scanf("%d", &g[a][j]);
  }
  for(i=1;i<=k;i++){
    if(!x[i]) dfs(i);
  }
  for(i=1;i<=k;i++){
    printf("%d %d %d\n", i, x[i], y[i]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int MAX_N = 100;
const int INF = 1e9;

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

int t = 1;

void dfs(int v) {
    if (d[v] == INF) d[v] = t++;
    for (auto u : g[v]) {
        if (d[u] == INF) dfs(u);
    }
    if (f[v] == INF) f[v] = t++;
}

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

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

void dfs_init();
void dfs(int u);

int n,*d,*f,time;
string *color; bool **M;

int main(){
	cin>>n;
	color = new string[n];
	M = new bool*[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	d = new int[n]; f = new int[n];

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

	int deg,vertex,temp;
	for(int i=0;i<n;i++){
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>temp;
			M[vertex-1][temp-1] = true;
		}
	}

	dfs_init();

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

	delete [] color;
	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] f;
}

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

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=0;v<n;v++){
		if(M[u][v] && color[v]=="WHITE")
			dfs(v);
	}
	color[u] = "BLACK";
	f[u] = ++time;
}