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++: #include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

vector<int> d(100, 1), f(100);

int dfs(vector<vector<int>> a, int s) {
	int n = a.size();
	int res = 0;
	REP(j, n) {
		if (d[j] == 1 && a[s][j]) {
			if (res == 0) {
				d[j] = d[s] + 1;
			}
			else {
				d[j] = res;
			}
			res = dfs(a, j) + 1;
		}
	}
	if (res == 0) return f[s] = d[s] + 1;
	return f[s] = res;
}

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

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

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAXN = 1000;
int n;
int d[MAXN];
int f[MAXN];
int t;
void solve(int current,vector<vector<int> > &g){
  if(d[current] > 0)return;
  t++;
  d[current] = t;
  for(int next:g[current]){
    solve(next,g);
  }
  t++;
  f[current] = t;
}

int main(){
  cin >> n;
  vector<vector<int> > g(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;
      g[i].push_back(v);
    }
  }
  solve(1,g);
  for(int i = 1;i <= n;i++){
    cout << i << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

C++: /*16D8103008D 西村悠輝　nissy0507barista  alds11_B*/ 

#include<iostream>

#define MAX 110
using namespace std;

int n,v,k,u; ///超点数、頂点番号、出次数、隣接
int d[MAX], f[MAX];///タイムスタンプ
int a[MAX][MAX];
int cnt=0;
int flag[MAX]; ///通ったかどうか

void dfs(int x) {

	if (flag[x] == 1)return;
	cnt++;
	d[x] += cnt;
	flag[x] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[x][i] == 1 && flag[i] == 0) dfs(i);
	}
	cnt++;
	f[x] += cnt;

}

int main(void)
{
	cin >> n;

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

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

	return 0;
}

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

int n;
int g[101][101];
char c[101];
int visit[101];
int finish[101];
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[u][v] = 1;
        }

    }

   stack<int> s;
    for (int l = 1; l <= n; ++l) {
        c[l] = 'w';

    }
    int time = 0;
    int start = 0;
    int v;
    while(true) {
        start++;
        if(start == n) break;
        if(c[start] == 'w') {
            time++;
            s.push(start);
            c[start] = 'g';
            visit[start] = 1;
            while (s.size() != 0) {
                time++;
                v = s.top();
                int next = -1;
                for (int i = 1; i <= n ; ++i) {
                    if(i == v) {
                        continue;
                    }
                    if(g[v][i] && c[i] == 'w') {
                        next = i;
                        break;
                    }
                }
                if(next == -1) {
                    c[v] = 'b';
                    finish[v] = time;
                    s.pop();
                } else {
                    c[next] = 'g';
                    visit[next] = time;
                    s.push(next);
                }
            }
        }
    }

    for (int m = 1; m <= n; ++m) {
        cout << m << " " << visit[m ] << " " << finish[m] << endl;

    }



    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t) {
    visited[s] = true;
    ans[s].first = t;
    REP(i, g[s].size()) {
        if (visited[g[s][i]]) continue;
        t = dfs(g[s][i], t + 1);
    }
    t++;
    ans[s].second = t;
    return t;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        int u, m;
        cin >> u >> m;
        REP(j, m) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1, T = 0; i <= n; i++) {
        if (visited[i]) continue;
        T = dfs(i, T+1);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}