Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

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

int N;
int G[101][101];
int visited[101];

int start[101], complete[101];

int dfs(int v, int t) {
    visited[v] = 1;
    start[v] = t;
    int nt = t+1;
    for (int j = 0; j <= N; ++j) {
        if (!visited[j] && G[v][j]) {
            nt = dfs(j, nt);
        }
    }
    complete[v] = nt;
    return nt+1;
}

int main() {
    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int j = 0; j <= N; ++j) visited[j] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int tt = 1;
    for (int j = 1; j <= N; ++j) {
        if (!visited[j]) tt = dfs(j, tt);
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << start[j] << " " << complete[j] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], f[101];
int t = 0;

void dfs(int u, int n)
{
	color[u] = 1;
	d[u] = ++t;
	for (int v = 1; v <= n; v++) {
		if (G[u][v] && color[v] == 0)
			dfs(v, n);
	}
	color[u] = 1;
	f[u] = ++t;
}

int main(void)
{
	int n, k, v, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (color[i] == 0)
			dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: // ALDS1_11_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

vector<vector<int>> node(101);
vector<int> setu(101);
vector<bool> seen(101,false); 
vector<int> start(101,0);
vector<int> goal(101,0);
int t=0;
void dfs(int x){
    if(seen[x]==true) return;
    seen[x]=true;
    t++;
    start[x]=t;
    rep(i,setu[x]){
        dfs(node[x][i]);
    }
    t++;
    goal[x]=t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    rep(i,n){
        int u,k;
        cin>>u>>k;
        rep(j,k){
            int v;
            cin>>v;
            node[u].push_back(v);
            setu[u]=k;
        }
    }
    for(int i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<start[i]<<" "<<goal[i]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 105;

int t = 0;
pair<int, int> ans[MAX];
bool seen[MAX];
vector<int> to[MAX];

void dfs(int u) {
  if (seen[u]) return;
  seen[u] = true;
  ans[u].first = ++t;
  for (int v: to[u]) {
    dfs(v);
  }
  ans[u].second = ++t;
}

int main() {
  int n, u, k, v;
  cin >> n;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v;
      to[u].push_back(v);
    }
  }

  rep(i, n+1) seen[i] = false;
  FOR(i, 1, n+1) sort(to[i].begin(), to[i].end());

  FOR(i, 1, n+1) dfs(i);

  FOR(i, 1, n+1) {
    cout << i << " " << ans[i].first << " " << ans[i].second << endl;
  }



  
  return 0;
}

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

int main()
{
 int i;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int c;
vector<int> E[SIZE];
int d[SIZE],f[SIZE]; //init:0

void dfs(int v){
  c++;
  d[v]=c;
  for(int to : E[v]) if(d[to] == 0){
    dfs(to);
  }
  c++;
  f[v] = c;
}

int n;

int main(){
  cin >> n;
  rep(i,0,n){
    int v,k;
    cin >> v >> k;
    rep(i,0,k){
      int u;
      cin >> u;
      //E[u].push_back(v);
      E[v].push_back(u);
    }
  }

  rep(i,0,n){
    if(d[i+1] ==0) dfs(i+1);
  };

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

  return 0;
}

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

int main(){
  vector <vector<int> > path_field;
  int n;

  cin >> n; n++;
  path_field.resize(n);
  for(int i=1;i<n;i++){
    path_field[i].resize(n);
    for(int j=1;j<n;j++){
      path_field[i][j]=0;
    }
  }
  for(int i=1;i<n;i++){
    int _m,m;

    cin >> _m >> m;
    for(int j=0;j<m;j++){
      int to;
      
      cin >> to;
      path_field[i][to]=1;
    }
  }

  vector <tuple<int,int> > ans;
  deque <int> stk;
  int sarched_point,sum=0;

  ans.resize(n);
  for(int i=1;i<n;i++){
    ans[i]=make_tuple(0,0);
  }
  for(int i_=1;i_<n;i_++){
    if(get<0>(ans[i_])==0){
      stk.push_back(i_);
      if(sum!=0) sum++;
    }
  
    while(!stk.empty()){
      sarched_point = stk.back();
      sum++;

      if(get<0>(ans[sarched_point])==0){
        get<0>(ans[sarched_point])=sum;
      }
      for(int i=1;i<n;i++){
        if((path_field[sarched_point][i]==1)&&(get<0>(ans[i])==0)){
          stk.push_back(i);
       	  break;
        }else if(i==(n-1)){
          get<1>(ans[sarched_point])=sum+1;
          stk.pop_back();
        }
      }
    }
  }

  for(int i=1;i<n;i++){
    cout << i << " " << get<0>(ans[i]) << " " << get<1>(ans[i]) << endl;
  }
}