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
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			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
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	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<cstring>
#include<stack>
using namespace std;

int M[101][101], sta[101], en[101], n;
stack<int>S;

void dfs()
{
	int id, op;
	bool have;
	id = op = 1;

	while (true)
	{ 
		if (sta[id] == 0)          
		{
			S.push(id);
			sta[id] = op++;
		}

		have = false;
		
		for (int pid = 1; pid <= n; pid++)
		{
			if (M[id][pid] == 1 && sta[pid] == 0)     
			{
				id = pid;
				have = true;
				break;
			}
		}

		if (!have)
		{
			S.pop();
			en[id] = op++;

			if (!S.empty())
				id = S.top();
			else
			{
				for (int i = 1; i <= n; i++)
				{
					if (sta[i] == 0)
					{
						id = i;
						break;
					}		
				}			
			}
		}

		if (op > 2 * n)
			break;
	}
}

int main()
{
	int id, pid, k;

	memset(M, 0, sizeof(M));
	memset(sta, 0, sizeof(sta));
	memset(en, 0, sizeof(en));

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> id >> k;

		for (int j = 1; j <= k; j++)
		{
			cin >> pid;
			M[id][pid] = 1;
		}
	}

	dfs();

	for (int i = 1; i <= n; i++)
		cout << i << " " << sta[i] << " " << en[i] << endl;

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> G;
vector<bool> seen;
vector<int> d,f;
void DFS(int v,int& time){
    d[v]=time++;
    seen[v]=1;
    for(auto p:G[v]){
        if(seen[p])continue;
        DFS(p,time);
    }
    f[v]=time++;
}
int main(){
    scanf("%d",&n);
    seen=vector<bool>(n);
    d=f=vector<int>(n);
    G=vector<vector<int>>(n,vector<int>());
    for(int i=0;i<n;i++){
        int v,k;scanf("%d%d",&v,&k);
        for(int j=0;j<k;j++){
            int a;scanf("%d",&a);
            G[v-1].push_back(a-1);
        }
    }
    for(int i=0;i<n;i++) sort(G[i].begin(),G[i].end());
    int time=1;
    for(int i=0;i<n;i++){
        if(!seen[i])DFS(i,time);
    }
    for(int i=0;i<n;i++){
        printf("%d %d %d\n",i+1,d[i],f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[g[now][i]]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  else return;
  //cout << n << endl;
  for(int i=1;i<=n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    dfs(i);
  }
  for(int i=1;i<=n;i++){
    cout << i << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

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

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N], fs[MAX_N];

/* subroutines */

int dfs(int u, int t) {
  ds[u] = ++t;

  for (int i = 0; i < nbrs[u].size(); i++) {
    int &v = nbrs[u][i];
    if (! ds[v]) t = dfs(v, t);
  }

  return (fs[u] = ++t);
}

/* main */

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

  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    u--;

    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      v--;
      nbrs[u].push_back(v);
    }
  }

  int t = 0;
  for (int i = 0; i < n; i++)
    if (! ds[i]) t = dfs(i, t);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i + 1, ds[i], fs[i]);

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 101
using namespace std;

int g[N][N]; 
int d[N];
int f[N];
int n;
int times=0;
bool us[N];

//dfs
void dfs(int x){
  
  times++;
  d[x]=times;

  for(int i=1;i<=n;i++){
    if(g[x][i]==1 &&us[i]==false){
      us[i]=true;
      // cout <<"i "<<i<<endl;
      dfs(i);
    }
  } 
  f[x]=times=times+1;

}


int main(){
  
  int n2,data,u;

  //load n
  cin >>n;
  
  //initialize
  for(int i=0;i<N;i++){
    us[i]=false;
    for(int j=0;j<N;j++){
      g[i][j]=0;
    }
  }
  
  //load data
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&n2);
    for(int j=0;j<n2;j++){
      scanf("%d",&data);
      g[u][data]=1;
    }
  }
  
  //execute
  dfs(1);

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