Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

vll d(100, -1), f(100, -1);
vvll edges(100, vll());
ll n;

ll dfs(ll i, ll t) {
  if (d.at(i) != -1) return t-1;
  d.at(i) = t;
  REP(toi, edges.at(i).size()) {
    t = dfs(edges.at(i).at(toi), ++t);
  }
  return f.at(i) = t+1;
}

int main() {
  cin >> n;
  REP(i, n) {
    ll u, k; cin >> u >> k;
    REP(j, k) {
      ll to; cin >> to;
      edges.at(u-1).push_back(to-1);
    }
  }
  ll t = 0;
  REP(i, n) {
    t = dfs(i, t+1);
  }
  REP(i, n) {
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dfs(const vector<vector<int>>& edges, vector<int>& ds, vector<int>& fs, int u, int& t) {
    if (ds[u] > 0) {
        return;
    }
    ds[u] = ++t;
    for (auto v : edges[u]) {
        dfs(edges, ds, fs, v, t);
    }
    fs[u] = ++t;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(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;
            v--;
            edges[u].push_back(v);
        }
        sort(begin(edges[u]), end(edges[u]));
    }
    vector<int> ds(n, -1);
    vector<int> fs(n, -1);
    int t = 0;
    dfs(edges, ds, fs, 0, t);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}

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