Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int tim;
int n;
stack<int> s;
void visit(int);

int main(){
	tim=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1; //?????¢??\
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=-1;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1; //?????????????????????????????????????????????
		}
	}
	 //????????¢?????¢?´¢
	for(i=0;i<n;i++){
		if(d[i]==-1) visit(i);
	}
	for(i=0;i<n;i++) cout<< i+1 <<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

void visit(int a){
	s.push(a); //?????¨??°
	if(d[a]==-1){
		d[a]=++tim;
	}
	for(int i=0;i<n;i++){
		if(map[a][i]==1 && d[i]==-1){ //?????¢?´¢
			visit(i);
		}
	}
	s.pop();
	f[a]=++tim;
}

C++: #include <iostream>
#define NODE_SIZE 101

using namespace std;

struct tStamp
{
    int dsc;    //discovery
    int fin;    //finish
};

void dfs(int node, int adj[][NODE_SIZE], tStamp s[], int *cnt, int n){
    s[node].dsc = *cnt;   *cnt += 1;
    for(int i = 1; i <= n; i++){
        if(adj[node][i] && s[i].dsc == 0){
            dfs(i, adj, s, cnt, n);
        }
    }
    s[node].fin = *cnt;   *cnt += 1;
}

int main(){
    int n, u, k, v, cnt = 1;
    int adj[NODE_SIZE][NODE_SIZE] = {};
    tStamp stamp[NODE_SIZE];

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

    for(int i = 1; i <= n; i++){
        if(stamp[i].dsc == 0){
            dfs(i, adj, stamp, &cnt, n);
        }
        cout << i << " " << stamp[i].dsc << " " << stamp[i].fin << endl;
    }

    return 0;
}

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

typedef vector<int> Adj_list;
typedef vector<Adj_list> Adj_lists;

class Timekeeper{
public:
  int found;
  int complete;

  Timekeeper(){
    found = 0;
    complete = 0;
  }
};
typedef vector<Timekeeper> Timekeepers;

void dfs(const int& i, const Adj_lists& adj_lists, Timekeepers& timekeepers, int& t){
  stack<int> s;
  s.push(i + 1);
  while(!s.empty()){
    // visit top of stack
    int visit = s.top();

    // if this node is not found in past, save the time.
    if(!timekeepers[visit-1].found){
      timekeepers[visit-1].found = ++t;
    }

    // find next adjecent which is not visited yet
    for(const int& adj_list : adj_lists[visit-1]){
      if(!timekeepers[adj_list-1].found){
        s.push(adj_list);
        break;
      }
    }

    // if no adj found, delete this node
    if(visit == s.top()){
      timekeepers[visit-1].complete = ++t;
      s.pop();
    }
  }
}

int main(){

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

  Adj_lists adj_lists(n);
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    Adj_list adj_list(k);
    for(int j=0; j<k; j++){
      int v;
      scanf("%d", &v);
      adj_list[j] = v;
    }
    sort(adj_list.begin(), adj_list.end());
    adj_lists[u-1] = adj_list;
  }

  Timekeepers timekeepers(n);
  int t = 0;
  for(int i = 0; i < n; i++){
    if(!timekeepers[i].found) dfs(i, adj_lists, timekeepers, t);
  }

  for(int i = 0; i < timekeepers.size(); i++){
    printf("%d %d %d\n", i+1, timekeepers[i].found, timekeepers[i].complete);
  }

  return 0;
}

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

int N;
int D[110];
int G[110][110];
int F[110];
int t = 1;
void dfs(int cur){
	D[cur] = t;
	t++;
	for(int i=0;i<N;i++){
		if(G[cur][i] && D[i]==0){
			dfs(i);
		}
	}
	F[cur] = t;
	t++;
}


int main(){
	while(cin >> N && N>0){
		vector<vector<int> > g(110,vector<int>(110,0));
		int u,k;
		for(int i=0;i<N;i++){
			cin >> u >> k;
			for(int j=0;j<k;j++){
				int a;
				cin >> a;
				g[u-1].push_back(a); 
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<g[i].size();j++){
				int f = g[i][j];
				G[i][f-1] = 1;
			}
		}
		dfs(0);
		for(int i=0;i<N;i++){
			if(D[i]==0){
				dfs(i);
			}
		}
		for(int i=0;i<N;i++){
			cout << i+1 << " " << D[i]  << " " << F[i] << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int n;
vector<vector<int>> adjacencyList;
enum state {New, Working, Done};
vector<state> status;
vector<int> startTime;
vector<int> endTime;
int t = 0;

vector<vector<int>> GetAdjacencyList(int n)
{
	vector<vector<int>> adjacencyList(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			adjacencyList[u][--v] = 1;
		}
	}
	return adjacencyList;
}

void DFS(int node)
{
	status[node] = Working;
	startTime[node] = ++t;
	for (int i = 0; i < n; i++) {
		if (adjacencyList[node][i] && status[i] == New) DFS(i);
	}
	status[node] = Done;
	endTime[node] = ++t;
}

int main()
{
	cin >> n;
	adjacencyList = GetAdjacencyList(n);
	status = vector<state>(n);
	startTime = vector<int>(n);
	endTime = vector<int>(n);
	for (int i = 0; i < n; i++) {
		if (status[i] != Done) DFS(i);
	}
	for (int i = 0; i < n; i++) cout << i + 1 << " " << startTime[i] << " " << endTime[i] << endl;
}