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 <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
int N, turn;
int d[111], f[111];
vector<vector<int>> G;

void dfs(int from) {
   d[from] = ++turn;
   for (int to : G[from]) {
      if (!d[to]) dfs(to);
   }
   f[from] = ++turn;
}

int main() {
   // 入力
   cin >> N;
   G = vector<vector<int>>(N);
   rep (i, N) {
      int u, k;
      cin >> u >> k;
      u--;
      rep (j, k) {
         int a;
         cin >> a;
         a--;
         G[u].push_back(a);
      }
   }

   rep (i, N) {
      if (!d[i]) dfs(i);
   }

   rep (i, N) {
      printf("%d %d %d\n", i+1, d[i], f[i]);
   }

   return 0;
}

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

int num = 1;
bool visited[1000];
vector<int> v[1000], seq[1000];
void dfs(int k){
    seq[k].pb(num++);
    if(visited[k]) return;
    visited[k] = 1;
    for (auto t : v[k]){
        if(visited[t]) continue;
        dfs(t);
    }
    seq[k].pb(num++); return;

}
int main(){
    int n; cin >> n;
    memset(visited, 0, sizeof(visited));
    for (int i = 0; i < n; i++){
        int x, y, z; cin >> x >> y;
        for (int j = 0; j < y; j++){
            cin >> z; v[x].pb(z);
        }
    }
    for(int i = 1; i <= n; i++)
        sort(v[i].begin(), v[i].end());
    dfs(1);
    for (int i = 1; i <= n; i++){
        cout << i << ' ';
        for (auto k : seq[i])
        cout << k << ' ';
        cout << '\n';
    }
}

C++: #include <iostream>
#include <vector>
#include <stack>

using namespace std;

struct Node {
    bool visit = false;
    vector<int> next;
    int position = 0;
    int start = 0;
    int end = 0;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].start == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        st.push(s);
        while (!st.empty()) {
            temp = st.top();
            if (node[temp].position < node[temp].next.size() && node[node[temp].next[node[temp].position]].visit == false) {
                node[node[temp].next[node[temp].position]].start = time++;
                st.push(node[temp].next[node[temp].position++]);
            }
            else {
                node[temp].visit = true;
                node[temp].end = time++;
                st.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

#define N 105

struct Node{
    string color;
    int d;
    int f;
};

struct Node node[N];
int tt;
int AdjMat[N][N];

void DFS(int u, int n){
    node[u].color = "gray";
    node[u].d = ++tt ;
    for (int v = 1; v <= n; v++){
        if ( AdjMat[u][v] == 0 ) continue;
        if ( node[v].color == "white") DFS(v, n);
    }
    node[u].color = "black";
    node[u].f = ++tt;
}

void DFS_init(int n){
    for (int i = 1; i <= n; i++){
        node[i].color = "white";
    }
    tt = 0;
    
    for (int i = 1; i <= n; i++){
        if (node[i].color == "white") DFS(i, n);
    }
    for (int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, node[i].d, node[i].f);
    }
}

int main(){
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; i++ ){
        for (int j = 1; j <= n; j++){
            AdjMat[i][j] = 0;
        }
    }
    
    for (int i = 1; i <= n; i++){
        int u, k, v;
        cin >> u >> k;
        if ( k == 0 ) continue;
        for (int j = 1; j <= k; j++){
            cin >> v;
            AdjMat[u][v] = 1;
        }
        
    }
    DFS_init(n);
    
    return 0;
}