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>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include<stack>
#include <algorithm>
using namespace std;
#define max 101
#define WHITE 0
#define BLACK 1
#define GRAY -1
int color[max],d[max],f[max];
int t,varry[max][max];
stack<int> s;
int next(int u){
  int nv=-1;
  for(int i=0;i<varry[u][0];i++){
    if(color[varry[u][i+1]]==WHITE){
      nv=varry[u][i+1];
      break;
    }
  }
  
  return nv;
}
void visit(int r){
  int u,v;
  s.push(r);
  color[r]=GRAY;
  d[r]=++t;
  while(!s.empty()){
    u=s.top();
    v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
	s.push(v);
	color[v]=GRAY;
	d[v]=++t;
      }
    }
    else{
      s.pop();
      color[u]=BLACK;
      f[u]=++t;
      
    }
  }
}
void dfs(int u){
  for(int i=1;i<=u;i++)
    if(color[i]==WHITE)visit(i);
}
int main(){
  int n,u;
  cin>>n;
  for(int k=0;k<n;k++){
    cin>>u;
    cin>>varry[u][0];
    for(int i=0;i<varry[u][0];i++)
      cin>>varry[u][i+1];

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


  return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

using Graph = vector<vector<int>>;

int g[101][101];
int seen[101];
int stamp[2][101];
int n;
int t;

void dfs(int v){
  seen[v] = 1;
  int ii;

  //cout << v << endl;
  
  stamp[0][v] = t;
  t++;

  //for(ii=1;ii<=n;ii++){
  //  cout << seen[ii] << endl;
  //}
  
  for(ii=1;ii<=n;ii++){
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(seen[ii] == 1){continue;}
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(g[v][ii] == 1){
      dfs(ii);
    }
  }
  
  stamp[1][v] = t;
  t++;
}

int main(){
  long ii,jj,kk;
  vector<int> a;


  memset(g,0,sizeof(g));

  memset(stamp,0,sizeof(stamp));
  
  cin >> n;

  int v,vn,r;
  
  for(ii=0;ii<n;ii++){
    cin >> v;
    cin >> vn;
    for(jj=0;jj<vn;jj++){
      cin >> r;
      g[v][r] = 1;
    }
  }

  //for(ii=1;ii<=n;ii++){
  //  for(jj=1;jj<=n;jj++){
  //    cout << g[ii][jj] ;
  //    if(jj!=n){
  //      cout << " ";
  //    }
  //  }
  //  cout << endl;
  //}  
  
  t = 1;
  memset(seen,0,sizeof(seen));

  for(ii=1;ii<=n;ii++){
    if(seen[ii] == 0){
      dfs(ii);
    }

  }


  for(ii=1;ii<=n;ii++){
    cout << ii << " " << stamp[0][ii] << " " << stamp[1][ii] << endl;
  }
  return 0;
}

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

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

    vector<vector<int>> edge(n);
    for (int i = 0; i < n; i++) {
        int m, c;
        cin >> m >> c;
        for (int j = 0; j < c; j++) {
            int x;
            cin >> x;
            edge[i].push_back(--x);
        }
    }

    int timestamp = 1;
    vector <int> d(n, -1), f(n, -1);
    auto dfs = [&](auto dfs, int cur) -> void {
        d[cur] = timestamp++;
        for (int ch : edge[cur]) {
            if (d[ch] == -1) {
                dfs(dfs, ch);
            }
        }
        f[cur] = timestamp++;
    };

    for (int i = 0; i < n; i++) {
        if (d[i] == -1) {
            dfs(dfs, i);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool visit[100];
int finish_time[100];
int find_time[100];
int t;
vector<int> E[100];
void dfs(int u){
  visit[u] = true;
  find_time[u] = ++t;
  for(int v : E[u]) if(!visit[v]) dfs(v);
  finish_time[u] = ++t;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    u--;
    rep(j,k){
      int v;
      cin >> v;
      v--;
      E[u].push_back(v);
    }
  }
  rep(i,n) if(!visit[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << find_time[i] << " " << finish_time[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

bool graph[100][100]={false};
int d[100],f[100];
bool visited[100]={false};
int t=0;
void dfs(int gsize,int now){
    if(visited[now]==false)d[now]=++t;
    visited[now]=true;

    for(int i=0;i<gsize;i++){
        if(graph[now][i]==true && visited[i]==false){
            dfs(gsize,i);
        }
    }
    f[now]=++t;
}
int main(void){
    int n;
    cin>>n;
    rep(i,0,n){
        int u,k;
        cin>>u>>k;
        u--;
        rep(j,0,k){
            int v;
            cin>>v;
            v--;
            graph[u][v]=true;
        }
    }
    rep(i,0,n){
        if(visited[i]==false)
            dfs(n,i);
    }
    rep(i,0,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int mat[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]+=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(mat[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	}
	t += 1; 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<100;i++){
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			mat[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			mat[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;i++){
    if(c[i]!=1){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++)
    {
      cout<<(i+1)<<' '<<mytime1[i]<<' '<<mytime2[i]<<endl;
    }
}