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

using namespace std;

int  n, M[100][100], d[100], f[100], color[100], tt, nt[100], W = 0, G = 1, B = 2;

int next (int u) {

    int v;
    for (v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v] != 0) {
            return v;
        }
    }
    return -1;

}

void dfs_visit (int r) {

    int i, u, v;

    for (i = 0; i < n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = G;
    d[r] = ++tt;

    while (!S.empty()) {
        u = S.top();
        v = next (u);
        if (v != -1) {
            if (color[v] == W) {
                color[v] = G;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = B;
            f[u] = ++tt;
        }
    }

}

void dfs () {

    int i, u;

    for (i = 0; i < n; i++) {
        color[i] = W;
        nt[i] = 0;
    }
    tt = 0;

    for (u = 0; u < n; u++) {
        if (color[u] == W) {
            dfs_visit(u);
        }
    }

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

}

int main () {

    int u, k, v, i, j;

    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs ();

    return 0;

}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll MOD = 998244353;

int t = 1, k[100], v[100][100], d[100], f[100];

void dfs(int x) {
    d[x] = t;
    t++;
    rep(i, k[x]) {
        int y = v[x][i];
        if (d[y] > 0) continue;
        dfs(y);
    }
    f[x] = t;
    t++;
}

int main() {
    int n, u;
    cin >> n;
    rep(i, n) {
        cin >> u;
        cin >> k[u - 1];
        rep(j, k[u - 1]) {
            cin >> v[u - 1][j];
            v[u - 1][j]--;
        }
    }
    rep(i, n) d[i] = 0;
    rep(i, n) if (d[i] == 0) dfs(i);
    rep(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
    }
}

C++: #include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 105;
const int INF = 1000;

vector<int> to[MAX_N];
int d[MAX_N], f[MAX_N]; // d：発見時刻、f：完了時刻
int t = 0; int n; 

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

void dfs(int u){
    if(d[u] == INF) d[u] = ++t;
    for(auto v: to[u]){
        if(d[v] == INF) dfs(v); // *もう訪問が完了している頂点には不要に寄らない
    }
    if(f[u] == INF) f[u] = ++t;
}

void dfs_init(){
    rep(i,n){
        if(d[i] == INF) dfs(i);
    }
}

int main()
{
    cin >> n;
    init();
    rep(i,n){
        int u, k; cin >> u >> k; --u;
        rep(_,k){
            int v; cin >> v; --v;
            to[u].push_back(v);
        }
    }
    dfs_init();
    rep(i,n){
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}

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

using namespace std;

vector<int> F;
vector<int> L;
vector<bool> seen;

void dfs(vector<vector<int>> &G,int v,int &t){
    F[v]=t++;

    seen[v]=true;

    for(int i=0;i<G[v].size();i++){
        if(seen[G[v][i]])continue;
        dfs(G,G[v][i],t);
    }

    L[v] = t++; 
}

int main(){

    int n;
    cin >> n;

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

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

    seen.assign(n,false);
    F.resize(n);
    L.resize(n);
    int t=1;
    
    

    for(int i=0;i<n;i++){
        if(!seen[i])dfs(G,i,t);
        cout << i+1 << " " << F[i] << " " << L[i] << endl;
    }

    return 0;




}

C++: #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int cnt = 1; // time stamp
vector<int> seen, visited;

void dfs(vector<vector<int> > graph, int v) {
    if (seen[v] != 0) return;
    seen[v] = cnt;
    cnt++;
    for (int i = 0; i < graph[v].size(); i++) {
        dfs(graph, graph[v][i]);
    }
    visited[v] = cnt;
    cnt++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n+1);
    for (int i = 1; i <= n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            graph[u].push_back(v);
        }
    }
    seen.assign(n+1, 0);
    visited.assign(n+1, 0);
    for (int i = 1; i <= n; i++) dfs(graph, i);
    for (int i = 1; i <= n; i++) {
        cout << i << " " << seen[i] << " " << visited[i] << endl;
    }
}