Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void dfs(int s, vector<vector<int>> a, vector<int> &d, vector<int> &f) {
	int n = a.size();
	int next = -1;
	REP(j, n) {
		if (!d[j] && a[s][j]) {
			if (next == -1) d[j] = d[s] + 1;
			else d[j] = f[next] + 1;
			next = j;
			dfs(j, a, d, f);
		}
	}
	if (next == -1) {
		f[s] = d[s] + 1;
	}
	else {
		f[s] = f[next] + 1;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n, 0));
	REP(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		REP(j, k) {
			int v;
			cin >> v;
			a[u][--v] = 1;
		}
	}
	vector<int> d(n, 0);
	d[0] = 1;
	vector<int> f(n);
	dfs(0, a, d, f);
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int t=1, n, M[100][100], color[100], d[100], f[100];
void dfs(int u){
	color[u]=1;
	d[u]=t;
	t++;
	for(int v=0; v<n; v++){
		if(M[u][v]==1 && color[v]==0){
			dfs(v);
		}
	}
	color[u]=2;
	f[u]=t;
	t++;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++){
		color[i]=0;
		d[i]=0;
		f[i]=0;
		for(int j=0; j<n; j++){
			M[i][j]=0;

		}
	}
	for(int i=0; i<n; i++){
		int u, k, child;
		cin>>u>>k;
		for(int j=0; j<k; j++){
			cin>>child;
			M[u-1][child-1]=1;
		}
	}
	for(int i=0; i<n; i++){
		if(color[i]==0)
			dfs(i);
	}
	for(int i=0; i<n; i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int timestamp = 1;

void dfs(int from, vector< vector<int> >& edges, vector<int>& d, vector<int>& f) {
    if(d[from] > 0) return;
    d[from] = timestamp++;
    for(int next: edges[from]) {
        if(d[next] == 0)
            dfs(next, edges, d, f);
    }
    f[from] = timestamp++;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int> > edges(N+1);
    REP(i, N) {
        int u, k;
        cin >> u >> k;
        edges[u].resize(k);
        REP(j, k) cin >> edges[u][j];
        sort(ALL(edges[u]));
    }

    vector<int> d(N+1), f(N+1);
    FOR(i, 1, N)
        dfs(i, edges, d, f);
    FOR(i, 1, N) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>

using namespace std;
int n;
list<int> adj[101];
int d[101] = {};
int f[101] = {};

void DFS(int v)
{
    static int num = 1;
    d[v] = num++;
    while (!adj[v].empty())
    {
        if (d[adj[v].front()] == 0)
            DFS(adj[v].front());
        adj[v].pop_front();
    }
    f[v] = num++;
}

void print()
{
    for (int i = 1; i <= n; i++)
    {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main()
{
    int u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u].push_back(v);
            k--;
        }
    }

    DFS(1);

    print();

    return 0;
}

C++: /* 
 * ALDS1_11B.cpp
 */
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int N;
int ad_k[101];
int ad_list[101][101];

int jikan = 0;
int d[101], f[101];
bool visited[101];

void visit(int id) {
    if (visited[id])
        return;

    visited[id] = true;
    d[id] = ++jikan;
    for (int i = 0; i < ad_k[id]; ++i) {
        visit(ad_list[id][i]);
    }
    f[id] = ++jikan;
}

int main(void) {

    scanf("%d", &N);
    for (int i = 1, id; i <= N; ++i) {
        scanf("%d", &id);
        scanf("%d", ad_k + id);
        for (int j = 0; j < ad_k[id]; ++j) {
            scanf("%d", ad_list[id] + j);
        }
    }

    for (int i = 1; i <= N; ++i) {
        visit(i);
    }

    for (int i = 1; i <= N; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> PP;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[200];
int d[200] = {}, f[200] = {};

int func(int pos, int time){
  if(d[pos] > 0){
    return time;
  }
  d[pos] = time;
  time += 1;
  for(int to : E[pos]){
    time = func(to, time);
  }
  f[pos] = time;
  time += 1;
  return time;
}

int main(){
  int n;
  cin >> n;
  for(int loop = 0; loop < n; loop++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int v;
      cin >> v;
      E[u].push_back(v);
    }
  }
  int time = 1;
  for(int i = 1; i <= n; i++){
    if(d[i] == 0){
      time = func(i, time);
    }
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}