Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

static const int N = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;
int d[N], f[N],tt;
int color[N],n,M[N][N];


void dfs_visit(int u) {
	int v;
	d[u] = ++tt;
	color[u] = Gray;
	rep(v,n){
		if (M[u][v] == 0) continue;
		if (color[v] == White) dfs_visit(v);
	}
	color[u] = Black;
	f[u] = ++tt;
}

void dfs() {
	int u;
	rep(u, n)color[u] = White;
	rep(u, n) {
		if (color[u] == White) dfs_visit(u);
	}
	rep(u, n) {
		cout << u + 1 << ' ' << d[u] << ' ' << f[u] << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	int i;
	rep(i, n) {
		int u, k, v;
		cin >> u >> k;
		u--;
		int j;
		rep(j, k) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <stdio.h>
int n,M[100][100],C[100],d[100],f[100],t;
void visit(int );
void dfs();
int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}
void dfs(){
  int i;
  for(i=0;i<n;i++)C[i]=0;
  t=0;
  for(i=0;i<n;i++)if(C[i]==0)visit(i);
  for(i=0;i<n;i++)printf("%d %d %d\n",i+1,d[i],f[i]);
}
void visit(int k){
  int i;
  C[k]=1;
  d[k]=++t;
  for(i=0;i<n;i++){
    if(M[k][i]==0)continue;
    if(C[i]==0)visit(i);
  }
  C[k]=2;
  f[k]=++t;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0;v = n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] == BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    
    for(u = 0;u < n;u++) color[u] = WHITE;
    tt = 0;
    
    for(u = 0;u < n;u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n;u++){
        printf("%d %d %d\n",u + 1,d[u],f[u]);
    }
}

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

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

// 深さ優先探索
vector<bool> seen;
vector<int> start_ptr;
vector<int> end_ptr;
void dfs(const Graph &G, int v, int &ptr) {
    seen[v] = true;
    start_ptr[v]=ptr;
    ptr++;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, ptr); // 再帰的に探索
    }
    end_ptr[v]=ptr;
    ptr++;
}

int main() {
    // 頂点数と辺数
    int N; cin >> N;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        for(int j=0;j<b;j++){
            int v; cin >>v;
        
        G[a-1].push_back(v-1);
        }
    }

    // 全頂点が訪問済みになるまで探索
    seen.assign(N, false);
    int ptr=1;
    start_ptr.resize(N);
    end_ptr.resize(N);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v, ptr); // v が未探索なら v を始点とした DFS を行う
    }
    for(int i=0;i<N;i++){
    cout << i+1 <<" "<<start_ptr[i]<<" "<<end_ptr[i]<< endl;
    }
}

C++: #include<stdio.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt;
    for(v=0;v<n;v++){
        if(M[u][v]==0)continue;
        if(color[v]==WHITE){dfs_visit(v);}
    }
    color[u]=BLACK;
    f[u]=++tt;;
}
void dfs(){
    int u;
    for(u=0;u<n;u++)color[u]=WHITE;
    tt=0;
    for(u=0;u<n;u++){
        if(color[u]==WHITE)dfs_visit(u);
    }
    for(u=0;u<n;u++)printf("%d %d %d\n",u+1,d[u],f[u]);
}
int main(){
    int u,v,k,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)M[i][j]=0;
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }
    dfs();
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}