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++: // ALDS1_11_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

vector<vector<int>> node(101);
vector<int> setu(101);
vector<bool> seen(101,false); 
vector<int> start(101,0);
vector<int> goal(101,0);
int t=0;
void dfs(int x){
    if(seen[x]==true) return;
    seen[x]=true;
    t++;
    start[x]=t;
    rep(i,setu[x]){
        dfs(node[x][i]);
    }
    t++;
    goal[x]=t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    rep(i,n){
        int u,k;
        cin>>u>>k;
        rep(j,k){
            int v;
            cin>>v;
            node[u].push_back(v);
            setu[u]=k;
        }
    }
    for(int i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<start[i]<<" "<<goal[i]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 105;

int t = 0;
pair<int, int> ans[MAX];
bool seen[MAX];
vector<int> to[MAX];

void dfs(int u) {
  if (seen[u]) return;
  seen[u] = true;
  ans[u].first = ++t;
  for (int v: to[u]) {
    dfs(v);
  }
  ans[u].second = ++t;
}

int main() {
  int n, u, k, v;
  cin >> n;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v;
      to[u].push_back(v);
    }
  }

  rep(i, n+1) seen[i] = false;
  FOR(i, 1, n+1) sort(to[i].begin(), to[i].end());

  FOR(i, 1, n+1) dfs(i);

  FOR(i, 1, n+1) {
    cout << i << " " << ans[i].first << " " << ans[i].second << endl;
  }



  
  return 0;
}

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

int main()
{
 int i;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int c;
vector<int> E[SIZE];
int d[SIZE],f[SIZE]; //init:0

void dfs(int v){
  c++;
  d[v]=c;
  for(int to : E[v]) if(d[to] == 0){
    dfs(to);
  }
  c++;
  f[v] = c;
}

int n;

int main(){
  cin >> n;
  rep(i,0,n){
    int v,k;
    cin >> v >> k;
    rep(i,0,k){
      int u;
      cin >> u;
      //E[u].push_back(v);
      E[v].push_back(u);
    }
  }

  rep(i,0,n){
    if(d[i+1] ==0) dfs(i+1);
  };

  rep(i,0,n){
    cout << i+1 << " " <<  d[i+1] << " " << f[i+1] << endl;
  }

  return 0;
}

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

int main(){
  vector <vector<int> > path_field;
  int n;

  cin >> n; n++;
  path_field.resize(n);
  for(int i=1;i<n;i++){
    path_field[i].resize(n);
    for(int j=1;j<n;j++){
      path_field[i][j]=0;
    }
  }
  for(int i=1;i<n;i++){
    int _m,m;

    cin >> _m >> m;
    for(int j=0;j<m;j++){
      int to;
      
      cin >> to;
      path_field[i][to]=1;
    }
  }

  vector <tuple<int,int> > ans;
  deque <int> stk;
  int sarched_point,sum=0;

  ans.resize(n);
  for(int i=1;i<n;i++){
    ans[i]=make_tuple(0,0);
  }
  for(int i_=1;i_<n;i_++){
    if(get<0>(ans[i_])==0){
      stk.push_back(i_);
      if(sum!=0) sum++;
    }
  
    while(!stk.empty()){
      sarched_point = stk.back();
      sum++;

      if(get<0>(ans[sarched_point])==0){
        get<0>(ans[sarched_point])=sum;
      }
      for(int i=1;i<n;i++){
        if((path_field[sarched_point][i]==1)&&(get<0>(ans[i])==0)){
          stk.push_back(i);
       	  break;
        }else if(i==(n-1)){
          get<1>(ans[sarched_point])=sum+1;
          stk.pop_back();
        }
      }
    }
  }

  for(int i=1;i<n;i++){
    cout << i << " " << get<0>(ans[i]) << " " << get<1>(ans[i]) << endl;
  }
}

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

vector<int> *a;
bool *check;
int *d,*f;

int dfs(int u, int time){
    int i, v;
    check[u] = true;
    d[u] = time;
    time++;
    for(i=0;i<a[u].size();i++){
        v = a[u][i];
        if(!check[v])time = dfs(v,time);
    }
    f[u] = time;
    time++;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    check = (bool *)malloc(sizeof(bool)*(n+1));
    d = (int *)malloc(sizeof(int)*(n+1));
    f = (int *)malloc(sizeof(int)*(n+1));
    for(i=0;i<=n;i++)check[i] = false;
    a = (vector<int> *)malloc(sizeof(vector<int>)*(n+1));

    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            a[u].push_back(v);
        }
    }

    int time = 1;
    for(i=1;i<=n;i++){
        if(!check[i])
        time = dfs(i,time);
    }

    for(i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);

    return 0;
}