Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = t; }
}

int main() {
	cin >> n;
	for (int i = 0; i < n;i++) {
		int u,k; cin >> u >> k;
		for (int j = 0; j < k;j++) {
			int x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

C++: #include <bits/stdc++.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 visit(int a){
  int b;
  color[a]=GRAY;
  d[a]=++tt;
  for(b=0;b<n;b++){
    if(m[a][b]==0) continue;
    if(color[b]==WHITE) visit(b);
  }
  color[a]=BLACK;
  f[a]=++tt;
}

void dfs(){
  int a;
  for(a=0;a<n;a++) color[a]=WHITE;

  tt=0;

  for(a=0;a<n;a++){
    if(color[a]==WHITE) visit(a);
  }
  for(a=0;a<n;a++) printf("%d %d %d\n",a+1,d[a],f[a]);

}

int main(){
  int u,v,k,i,j;

  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) m[i][j]=0;
  }

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool graph[101][101];
int first_time[101],last_time[101];
int visited[101];
int tt=0;
int v[101][101];
#define white 0
#define gray 1
#define black 2//0回目の訪問、1回目の訪問、2回目の訪問の3種類あるからboolを使わない

void dfs(int v,int n) {
	for (int i = 2; i <= n; ++i) {
		if (graph[v][i] == false)continue;
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	visited[v] = black;
	++tt;
	last_time[v] = tt;

}

int main() {
	int n;
	cin >> n;
	int u, k;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v[u][j + 1];
			graph[u][v[u][j + 1]] = true;
		}
	}
	for (int i = 1; i <= n; ++i) {//1つの始点から全訪問可能とは限らないから
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << first_time[i] << " " << last_time[i] << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_NODE 101

int begin_times[MAX_NODE];
int end_times[MAX_NODE];
int c_time=0;
queue<int> g[MAX_NODE];

void dfs(int f){
  if(begin_times[f]>0)return;
  c_time++;
  begin_times[f]=c_time;
  while( !g[f].empty() ){
    int to = g[f].front();
    g[f].pop();
    if(end_times[to]>0)continue;
    dfs(to);
  }
  c_time++;
  end_times[f]=c_time;
}

int main(){
  int n;cin>>n;
  rep(i, n){
    int from;
    int count;
    cin>>from>>count;
    rep(j, count){
      int t;cin>>t;
      g[from].push(t);
    }
  }

  rep1(i, n)dfs(i);

  rep1(i, n){
    cout<<i<<' '<<begin_times[i]<<' '<<end_times[i]<<endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <stack>
#define MAX_VERTEXES 100
#define ZERO 0
#define NIL -1

using namespace std;

//think easy make easy

int n;//num of vertexes(頂点)
int matrix_graph[MAX_VERTEXES+1+1][MAX_VERTEXES+1+1];//1オリジン

stack<int> stk;
bool discovered[MAX_VERTEXES+1+1];//1オリジン
int discovered_time[MAX_VERTEXES+1+1];
int completed_time[MAX_VERTEXES+1+1];
int current_time = 0;

void DFS(int v){
	int v_tmp;
	for(int i=1;i<=n;i++){
		//if(i == v);
		else if(matrix_graph[v][i] == 1 && !discovered[i]){
			current_time++;
			discovered_time[i] = current_time;
			stk.push(v);
			matrix_graph[v][i] == 0;
			discovered[i] = true;
			DFS(i);
		}else if(matrix_graph[v][i] == 1 && discovered[i]){
			matrix_graph[v][i] == 0;
		}

		if(i == n){
			current_time++;
			completed_time[v] = current_time;
			//if(!stk.empty())
			//{
				//cout <<stk.top() <<endl;
				//v_tmp = stk.top();
				//stk.pop();
				//DFS(v_tmp);
			//}
		}
	}
}

int main(){
	scanf("%d",&n);

	int v_num;
	int k;//v_numの出次数

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			matrix_graph[i][j] = ZERO;
		}
	}

	for(int i=0;i<n;i++){
		scanf("%d",&v_num);
		scanf("%d",&k);

		for(int j=0;j<k;j++){
			int v_num2;
			scanf("%d",&v_num2);
			matrix_graph[v_num][v_num2] = 1;
		}
	}

	for(int i=1;i<=n;i++){
		discovered[i] = false;
		discovered_time[i] = NIL;
		completed_time[i] = NIL;
	}

	for(int i=1;i<=n;i++){
		current_time++;
		if(!discovered[i]){
			discovered[i] = true;
			discovered_time[i] = current_time;
			DFS(i);
		}
	}

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

	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;

struct node{
	int id;
	queue<node*> adjacentNodeList;
};

int d[100] = {0};
int f[100] = {0};

int bfs(node* nd,int time){
	//cout<<nd->id<<" is called"<<endl;
	if(f[nd->id] != 0){
		return time;
	}
	if(d[nd->id] != 0){
		return time;
	}
	time = time + 1;
	if(d[nd->id] ==0){
		d[nd->id] = time;
	}
	while( !nd->adjacentNodeList.empty() ){
		if(nd->id == nd->adjacentNodeList.front()->id){
			nd->adjacentNodeList.pop();
		}else{
			time = bfs(nd->adjacentNodeList.front(),time);
			nd->adjacentNodeList.pop();
		}
	}
	time++;
	if( f[nd->id] == 0) f[nd->id] = time;
	return time;
}

int main()
{
	int n;
	cin>>n;
	struct node *nodeList = new node[n];
	for(int i = 0; i < n; i++){
		nodeList[i].id = i;
	}

	for(int i = 0; i < n;i++){
		int u,k;
		cin>>u>>k;
		u--;		//0 origin
		for(int j = 0; j < k; j++){
			int index;
			cin>>index;
			index--;		//0 origin
			nodeList[u].adjacentNodeList.push(&nodeList[index]);
		}
	}
	int time = 0;
	for(int i = 0; i < n; i++){
		time = bfs(&nodeList[i],time);	
	}

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

	return 0;
}