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
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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<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() {
    int u, k, v, i, j;
    
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        M[i][j] = 0;
      } 
    }
    
    for(int i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++ ) {
           scanf("%d", &v);
           v--;
           M[u][v] = 1; 
        }       
    }
     
     
    dfs();
     
    return 0;
}

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

int n, dd[100], f[100], tmap[100][100];
int color[100], t = 1;
stack<int> S;

int a(){
	int d = S.top();
	dd[d] = t;
	t++;
	color[d] = 1;
	cout << d << "??????" <<endl;
	for (int i = 1; i <= n; i++){
		if (color[i] == 0 && tmap[d][i] == 1){
			cout << d << "  " << i << "  " << t << endl;
			S.push(i);
			a();
		}
	}
	cout << d << "??????" << endl;
	f[d] = t;
	t++;
	return 0;
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		dd[i] = f[i] = color[i] = 0;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	S.push(1);
	a();
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << " " << f[i] << endl;
	}
	return 0;
}

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<iostream>
#include<stack>
using namespace std;

stack<int> S;
int n, x[10000][10000], a, b, c, d, _time=2;
int y[10000][3];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			x[i][d] = 1;
			x[d][i] = 1;
		}
	}
	S.push(1);
	y[1][1] = 1;
	while (!S.empty()) {
		a = S.top();
		for (int i = 1; i <= n; i++) {
			if (x[a][i] == 1 && y[i][0] == 0) {
				y[i][0] = 1;
				y[i][1] = _time;
				S.push(i);
				goto Exit;
			}
		}
		S.pop();
		y[a][2] = _time;
	Exit:;
		_time++;
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << y[i][1] << ' ' << y[i][2] << endl;
	}
	return 0;
}

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

static const int M_NUM = 100;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int adj_M[M_NUM][M_NUM];
int v_num, Time(0);
int visit_state[M_NUM], D_time[M_NUM], C_time[M_NUM];

void DepthFirstSearch_Recursion(int vertex) 
{
    visit_state[vertex] = GRAY;
    D_time[vertex] = ++Time;
    for (int i = 0; i < v_num; ++i)
    {
        if (adj_M[vertex][i] && visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);
    }
    visit_state[vertex] = BLACK;
    C_time[vertex] = ++Time;
}

int main() 
{
    int v_id, v_degree, adj_v;
    cin >> v_num;

    for (int i = 0; i < v_num; ++i) 
    {
        for (int j = 0; j < v_num; ++j) 
        {
            adj_M[i][j] = 0;
        }
    }

    for (int i = 0; i < v_num; ++i) 
    {
        cin >> v_id >> v_degree;
        v_id--;
        for (int j = 0; j < v_degree; ++j) 
        {
            cin >> adj_v;
            adj_v--;
            adj_M[v_id][adj_v] = 1;
        }
    }

    for (int i = 0; i < v_num; ++i) visit_state[i] = WHITE;

    for (int i = 0; i < v_num; ++i) if (visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);

    for (int i = 0; i < v_num; ++i) 
    {
        cout << i + 1 << " " << D_time[i] << " " << C_time[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v;
vector<int> d,f,visited;
int cnt = 0;

void dfs(int node, vector<vector<int> > &graph)
{
  //cout << node+1 << " " << cnt+1 << "\n";
  d[node] = cnt;
  cnt++;
  visited[node] = 1;
  for(int i = 0; i<v[node].size(); i++)
  {
    if(visited[v[node][i]] == 1) continue;
    dfs(v[node][i], v);
  }
  //visited[node] = 0;
  //cout << node+1 << " " << cnt+1 << "\n";
  f[node] = cnt;
  cnt++;
}

int main()
{
  int n; cin>>n;
  d.resize(n, 0);
  f.resize(n, 0);
  visited.resize(n, 0);
  v.resize(n);
  for(int i=0; i<n; i++)
  {
    int id, u; cin>>id>>u;
    id--;
    v[i].resize(u);
    for(int j=0; j<u; j++)
    {
      int l; cin>>l;
      l--;
      v[id][j] = l;
    }
  }
  for(int i = 0; i < n; i++)
  {
    if (visited[i]) continue;
    else dfs(i, v);
  }
  for(int i = 0; i<n; i++)
  {
    cout << i+1 << " " << d[i] + 1 << " " << f[i] + 1 << "\n";
  }
  return 0;
}