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 <stdio.h>

int time, n;
int d[100], f[100], color[100];
int M[100][100];

void dfs(int u) {
    color[u] = 1;
    d[u] = ++time;
    for (int i=0; i<n; i++) {
        if(M[u][i] && color[i] == 0) {
            dfs(i);
        }
    }
    color[u] = 2;
    f[u] = ++time;
}

void dfs_init(){
    time = 0;
    for (int i=0; i<100; i++) color[i] = 0;
    dfs(0);
}

int main() {
    int u, k, v;
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            M[i][j] = 0;
        }
    }
    
    for (int i=0; i<n; i++) {
        scanf("%d %d", &u, &k);
        for (int j=0; j<k; j++) {
            scanf("%d", &v);
            M[u-1][v-1] = 1;
        }
    }
    
    dfs_init();
    
    for (int i=0; i<n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    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;
            graph[u].emplace_back(v);
        }
    }
    
    vector<bool> visited(n, false);
    vector<int> in(n), out(n);
    int T = 0;
    auto dfs = [&](auto&& self, int from) -> void {
        in[from] = ++T;
        visited[from] = true;
        for(int to : graph[from]){
            if(visited[to]) continue;
            self(self, to);
        }
        out[from] = ++T;
        return;
    };

    for(int i = 0; i < n; ++i){
        if(!visited[i]) dfs(dfs, i);
    }
    for(int i = 0; i < n; ++i){
        cout << i + 1 << ' ' << in[i] << ' ' << out[i] << '\n';
    }
}

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

int D[100];
int a[100][100];

int main() {
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
	  a[i][j] = 0;
	  }
	 }
	int n,u,k,v;
	cin >>n;
	for (int i = 0; i < n; i++) {
	  cin >> u >> k;
	  for (int j = 0; j < k; j++) {
	    cin >> v;
		a[u][v] = 1;
		}
	  }
queue<int> Q; //整数を管理するキューの定義
  for (int i = 1; i < n+1; i++){
   D[i] = -1;
   }
  int src = 1;
  Q.push(src);
  D[src] = 0; //出発点
  while (! Q.empty()) {
    int cur = Q.front(); //先頭要素を取り出す
	Q.pop();
	for (int dst = 1; dst <= n; dst++) {
    if((a[cur][dst] == 1 && D[dst] == -1)) { //curからdstに辺があり、dstが未訪問なら
	  D[dst] = D[cur] +1;
	  Q.push(dst);
	  }
	}
}

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

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

using namespace std;

const int N = 101;
bool marked[N];
int d[N];
int f[N];

void dfs(vector<vector<int>>& g, int vertex, int& counter) {
    if (marked[vertex])
        return;
    marked[vertex] = true;
    counter++;
    d[vertex] = counter;
    for (int x : g[vertex]) {
        if (!marked[x])
            dfs(g, x, counter);
    }
    counter++;
    f[vertex] = counter;
}

int main() {
    int n;
    cin >> n;

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

    int counter = 0;
    for (int i = 1; i <= n; i++)
        dfs(g, i, counter);

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

C++: //
//  main.cpp
//  619
//
//  Created by 8595198919 on 14/06/16.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#define _2
#ifdef _1
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;

int dist[105];
queue<int> que;
vector<int> G[105];
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        dist[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    que.push(1);
    dist[1]=0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int d = dist[now];
        rep(i,G[now].size()){
            if(dist[G[now][i]]==-1){
                dist[G[now][i]]=d+1;
                que.push(G[now][i]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout <<i <<" " << dist[i]<<endl;
    }
}
#endif

#ifdef _2

#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 0;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    for(int i = 1;i <= n;i++){
        if(d[i]==-1)
            tm++;
        dfs(1);
    }
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

#endif