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 <bits/stdc++.h>

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != 2) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int n;
vector<vector<int>> to, timestamp;

void dfs(int v, int& t) {
    timestamp[v][0] = t++;
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (timestamp[nv][0] > 0) continue;
        dfs(nv, t);
    }
    timestamp[v][1] = t++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    to.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            to[u].push_back(v);
        }
    }

    timestamp.resize(n, vector<int>(2, 0));
    int t = 1;
    rep(i, n) {
        if (timestamp[i][0] == 0) dfs(i, t);
    }

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

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int count = 1;
std::vector<vector<int> > G;
std::vector<int> flag;
std::vector<int> in;
std::vector<int> out;
int N;
int dfs(int u, int count) {
	flag[u] = 1;
	
	in[u] = count;
	for (int i = 0; i < N; ++i) {
		if (flag[i] == 0 && G[u][i] == 1) {
			count = dfs(i, count + 1);
		}
	}
	out[u] = count + 1;
	return count + 1;
}

int main(int argc, char const *argv[]) {
	
	cin >> N;

	for (int i = 0; i < N; ++i) {
		G.push_back(vector<int>());
		flag.push_back(0);
		in.push_back(0);
		out.push_back(0);
		for (int j = 0; j < N; ++j) {
			G[i].push_back(0);
		}
	}

	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--;
			G[u][v] = 1;
		}
	}

	dfs(0, 1);

	for (int i = 0; i < N; ++i) {
		cout << i + 1 << " " << in[i] << " " << out[i] << endl;
	}

	return 0;
}

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

int Stime = 0;
vector<int> edges[100];
bool visit[100];
int be[100]; //begin
int en[100]; //end


void dfs(int cur) //curを訪問
{
	//curの訪問時間を記録
	Stime++;
	visit[cur] = true;

	//cout << "visiting " << cur+1 << "  time:" << time << endl;
	be[cur] = Stime;

	for (int i = 0; i < edges[cur].size(); ++i)
	{
		if (!visit[edges[cur][i]])
		{
			dfs(edges[cur][i]);
		}
	}

	Stime++;

	//cout << "finished visiting " << cur+1 << "  time:" << time << endl;
	en[cur] = Stime;

}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 100; ++i)
	{
		visit[i] = false;
	}

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

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

	int temp = 0;
	int flag = true; //未探索のノードがあるかどうか
	while(flag)
	{
		dfs(temp);
		flag = false;
		for (int i = 0; i < n; ++i)
		{
			if (!visit[i])
			{
				temp = i;
				flag = true;
				break;
			}
		}
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i+1 << " " << be[i] << " " << en[i] << endl;
	}
	return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

#define white 0
#define gray 1

int M[110][110];
vector<int> color(110,white),d(110),f(110);
int t=0;
int n;

void dfs(int u){
  color[u]=gray;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v] && color[v]==white) dfs(v);
  }
  f[u]=++t;
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=0;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    x--;
    rep(j,y){
      cin>>z;
      z--;
      M[x][z]=1;
    }
  }

  rep(i,n){
    if(color[i]==white) dfs(i);
  }
  
  rep(i,n) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  
  return 0;
}