Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: #include <cstdio>
int dt[101][101];
int d[101], f[101];

int n;
int t=2;
void dfs(int s){
	for(int i=1;i<=n;i++){
		if(dt[s][i]&&d[i]==0){
			d[i]=t;
			t++;
			dfs(i);
		}
	}
	f[s]=t++;
}
int main(){
	int fi, v, g;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&fi,&v);
		for(int j=1;j<=v;j++){
			scanf("%d",&g);
			dt[fi][g]=1;
		}
	}
	d[1]=1;
	dfs(1);
	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int dfs(int from, int turn, vector<vector<int>> &tos, set<int> &used, vector<vector<int>> &ans) {
    used.erase(from);
    ans[from][1] = turn;
    for (int to : tos[from]) {
        if (contain(used, to)) {
            turn = dfs(to, turn + 1, tos, used, ans);
        }
    }
    turn++;
    ans[from][2] = turn;
    return turn;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> tos(n);
    rep(i, n) {
        int j, k;
        cin >> j >> k;
        j--;
        rep(l, k) {
            int m;
            cin >> m;
            m--;
            tos[j].push_back(m);
        }
    }

    vector<vector<int>> ans(n, vector<int>(3, 0));

    rep(i, n) sort(tos[i].begin(), tos[i].end());
    set<int> used;
    rep(i, n) used.insert(i);
    int turn = 0;
    while (!used.empty()) turn = dfs(*used.begin(), turn + 1, tos, used, ans);

    rep(i, n) ans[i][0] = i + 1;
    rep(i, n) print_line(ans[i]);
}

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

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

  vector<int> list[100];

  for(int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for(int j=0;j<k;j++){
      int v;
      cin >> v;
      list[u-1].push_back(v-1);
    }
  }
  
  int d[100],f[100];
  for(int i=0;i<n;i++) d[i]=f[i]=0;

  stack<int> cur;
  cur.push(0);
  d[0]=1;

  for(int t=2;!cur.empty();t++){
    bool fl=false;
    for(vector<int>::iterator it=list[cur.top()].begin();it!=list[cur.top()].end();it++){
      if(d[*it]==0){
        d[*it]=t;
        fl=true;
        cur.push(*it);
        break;
      }
    }
    if(fl) continue;

    f[cur.top()]=t;
    cur.pop();

    if(cur.empty()){
      for(int i=0;i<n;i++){
        if(d[i]==0){
          t++;
          cur.push(i);
          d[i]=t;
          break;
        }
      }
    }
  }

  for(int i=0;i<n;i++)
    cout << (i+1) << ' ' << d[i] << ' ' << f[i] << endl;

  return 0;
}

C++: a

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

int n, u;
int k[101], b[101], d[101], f[101];
int a[101][101];
int t = 1;

void dfs(int v){
    d[v] = t;
    t++;
    b[v]++;
    for(int l=0; l<k[v]; l++){
        if(b[a[v][l]] == 0){
            dfs(a[v][l]);
        }
    }
    f[v] = t;
    t++;
}


int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u >> k[u];
        for(int j=0; j<k[u]; j++){
            cin >> a[u][j];
        }
    }
    for(int v=1; v<=n; v++){
        if(b[v] == 0){
            dfs(v);
        }
        cout << v << " " << d[v] << " " << f[v] << endl;
    }
    return 0;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-12 18:24:44
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-12 18:38:47
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e2+10;

int d[MAXN],f[MAXN],a[MAXN][MAXN],n,cnt,u,v,t,book[MAXN];

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

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		cin>>u>>t;
		for(int j = 0; j < t; ++j)
		{
			cin>>v;
			a[u][v] = 1;
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i)
	{
		cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
	}
	return 0;
}

C++: #include <iostream>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
        for (int i = 0; i < n; i++) {
            if (adj_matrix[v][i] != 0) {
                dfs(i, n);
            }
        }
        if (f[v] == 0) {
            f[v] = t;
            t++;
        }
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj_matrix[i][j] = 0;
        }
    }

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

    for (int i = 0; i < n; i++) {
        dfs(i, n);
    }

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

    return 0;
}

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

vector<int> G[100];
pair<int, int> T[100];
const int Inf = 10000*100000+100;
int timer = 1;

int main() {
  void dfs(int cur);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int l = 0; l < k; l++) {
      int v;
      cin >> v;
      G[i].push_back(v - 1);
    }
    T[i] = make_pair(Inf, Inf);
  }
  for (int i = 0; i < n; i++) {
    if (T[i].first == Inf) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << T[i].first << " " << T[i].second << endl;
  }
}

void dfs(int cur) { // cur を訪問
  // cur の訪問時刻を記録
  T[cur].first = timer;
  timer += 1;
  // 動作確認用表示
  for (int dst : G[cur]) { // 全ての節点 dst について
    if (T[dst].first == Inf)
    { // cur から dst に辺があり，dst を未訪問なら
      dfs(dst);
    }
  }
  T[cur].second = timer;
  timer += 1;
}