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

using namespace std;

void DFS(vector<vector<int>>& graph, int v, int& time, vector<int>& d, vector<int>& f){
    time++;
    d[v] = time;
    for( int i = 0 ; i < graph[v].size(); i++){
        if(d[graph[v][i]] == -1){
            DFS(graph, graph[v][i], time, d, f);
        }
    }

    time++;
    f[v] = time;

    return;
}

int main(){

    int n;
    cin >> n;

    vector<vector<int>> graph(n);

    for(int i = 0; i < n; i++ ){
        int v, k;
        cin >> v >> k;
        for(int j = 0; j < k ; j++){
            int v2;
            cin >> v2;
            graph[v-1].push_back(v2-1);
        }
    }

    vector<int> d(n, -1);
    vector<int> f(n, -1);
    int time = 0;

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

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;
using vint = vector<int>;

void dfs(int k, int &t, vector<vector<int> >&g, vector<int>&d, vector<int>&f){
  d[k] = t;
  for(int i = 0; i < g[k].size(); i++){
    if(d[g[k][i]] == -1) dfs(g[k][i], ++t, g, d, f);
  }
  f[k] = ++t;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vector<vector<int> > g(n);
  vector<int> d(n, -1);
  vector<int> f(n, -1);
  for(int i = 0; i < n; i++){
    int t, k; cin >> t >> k;
    for(int j = 0; j < k; j++){
      int v; cin >> v;
      v--;
      g[i].push_back(v);
    }
  }
  int a = 0;
  for(int i = 0; i < n; i++){
    if(d[i] == -1) dfs(i, ++a, g, d, f);
  }
  for(int i = 0; i < n; i++){
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjlist;
int time=1;
vector<int> d;
vector<int> f;
void input(int n){
	vector<int> f={0,0};
	adjlist.push_back(f);
  for(int i=0;i<n;i++){
    vector<int> list;
    int ln;
    cin>>ln;
    list.push_back(ln);
    cin>>ln;
    list.push_back(ln);
    for(int j=0;j<ln;j++){
      int an;
      cin>>an;
      list.push_back(an);
    }
    adjlist.push_back(list);
  }
}

void depth_search(int id){
	vector<int> list=adjlist[id];
	for(int j=0;j<list[1];j++){
		if(d[list[2+j]]<0){
			d[list[2+j]]=++time;
			depth_search(list[2+j]);
		}
	}
	f[id]=++time;
}
 
void print(int n){
  for(int i=1;i<n+1;i++){
    cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
  }
}
int main(){
  int n;
  cin>>n;
	d=vector<int> (n+1,-1);
	f=vector<int> (n+1,-1);
	d[1]=1;
	f[1]=1;
  input(n);
  depth_search(1);
  print(n);
  return 0;
}

C++: #include <iostream>

using namespace std;
int n,u,k,v,**M,flag[100],s_time[100],f_time[100];
void creat()
{
    cin>>n;
  M=new int*[n];
  for(int i=0;i<n;i++)
    {
      M[i]=new int[n];
      flag[i]=0;
      for(int j=0;j<n;j++)
	M[i][j]=0;
    }
  int count=0;
  while(count<n)
    {
      count++;
      cin>>u>>k;
      for(int i=0;i<k;i++)
	{
	  cin>>v;
	  M[u-1][v-1]=1;
	}
    }
    /*for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)
      cout<<M[i][j]<<' ';
    cout<<endl;
  }*/
}
int time = 0;
void dfs(int cur) {
    time += 1;
    s_time[cur]=time;
    //cout << "visiting " << cur+1 << ' ' << time << endl;
    flag[cur]=1;
    for (int dst=0;dst<n;dst++) {
            if (M[cur][dst]&&!flag[dst]) {
                dfs(dst);
            }
    }
    time += 1;
    f_time[cur]=time;
}
int main()
{
    creat();
    for(int i=0;i<n;i++)
    {
        if(!flag[i])
            dfs(i);
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<' '<<s_time[i]<<' '<<f_time[i]<<endl;
    }
    delete M;
    return 0;
}

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

typedef long long llint;
typedef long double ld;
typedef pair<int,int> P;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)


priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


#define N 100

int g[N][N];
int d[N];
int f[N];
int t=0;


bool flag[N];
int n;

void dfs(int i){
    flag[i]=true;
    d[i]=++t;
    rep(j,0,n){
        if(g[i][j]==1 && !flag[j]){
            dfs(j);
        }
    }
    f[i]=++t;
}

void solve(){
    cin >> n;
    int u,k;
    rep(i,0,n){
        cin >> u >> k;
        u--;
        rep(j,0,k){
            int v;
            cin >> v;
            v--;
            g[u][v]=1;
        }
    }
    rep(i,0,n){
        if(!flag[i]){
            dfs(i);
        }
    }
    rep(i,0,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(){
    solve();
    return 0;
}

C++: 
#include <iostream>

using namespace std;

int d[100]={0},f[100]={0};
int k[101],v[101][100],n;
int c;
void solve();
void dfs(int point);

int main()
{
	cin>>n;
	for (int i=0; i<n; i++) {
		int t;
		cin>>t;
		cin>>k[t];
		for (int j=0; j<k[t]; j++) {
			cin>>v[t][j];
		}
	}
	solve();
}

void solve() {
	d[1]=1,c=2;
	for (int i=0; i<k[1]; i++) {
		if (d[v[1][i]]==0) {
			dfs(v[1][i]);
		}
	}
	c++;
	f[1]=c;
	for (int i=0; i<n; i++) {
		cout<<i+1<<' '<<d[i+1]<<' '<<f[i+1]<<endl;
	}
}
void dfs(int point)
{
	d[point]=c;
	int i=0;
	c++;
	while (i<k[point]) {
		if (d[v[point][i]]==0) {
			dfs(v[point][i]);
			c++;
		}
		i++;
	}
	if (f[point]==0) {
		f[point]=c;
	}
}