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 <bits/stdc++.h>
using namespace std;
vector<int> d;
vector<int> f;
vector<bool> used;
vector< vector<int> > v;
int n;
int cnt = 1;

void dfs(int pos){
  d[pos] = cnt; cnt++;
  used[pos] = true;
  for(int i = 0; i < n; i++){
    if(v[pos][i] && !used[i]){
      dfs(i);
    }
  }
  f[pos] = cnt; cnt++;
}

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

  cin >> n;
  d = f = vector<int>(n, -1);
  used = vector<bool>(n, false);
  v = vector< vector<int> >(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }
  for(int i = 0; i < n; i++)
    if(!used[i]) dfs(i);
  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;
}

C++: //ノードが持つ情報→子のノードの情報
//ノードが子を持たないときはからのvectorを保持する
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

//このようにクラスやストラクトなどで一括で管理してしまえば良い
class Node{//普通の木用のデータ
//ノードはポインタでもっておこう
public:
  ///ノードの番号
  int num;
  //そのノードの親
  Node* p;
  //そのノードの子
  vector<Node*> v;
  //そのノードの発見時刻と完了時刻(これは分けて配列の方がいいかもしれない)
  //int d=0;int f=0;
};

//木じゃないのでrootがあるわけじゃない(重要)

//見つからなかったら-1
//非連結な場合もあるので
int find_next_root(vector<int> va){
  int l= int(va.size());
  for(int i=0;i<l;i++){
    if(va[i]==0){return i;}
  }
  return -1;
}


//Nは始まりのNode
//tはmainで管理しするので
void depth_search(Node& N,int& t,vector<int>& va,vector<int>& vf){
  //呼ばれた前の時点での時間が与えられる
  //子を全部見終わったら、そのノードも足し算してそこで終了する
  t++;
  va[N.num]=t;
  int l=N.v.size();
  for(int i=0;i<l;i++){
    if(va[N.v[i]->num]==0) depth_search(*(N.v[i]),t,va,vf);
  }
  t++;
  vf[N.num]=t;
}


int main(){
  int n;cin>>n;
  vector<Node> V(n);for(int i=0;i<n;i++){V[i].num=i;}
  vector<int> Va(n,0);vector<int> Vf(n,0);

  for(int i=0;i<n;i++){
    int k;cin >> k >> k;
    for(int j=0;j<k;j++){
      int l;cin >>l;l-=1;
      V[l].p=&V[i];
      V[i].v.push_back(&V[l]);
    }
  }
  //初めは一つのグラフだと思ってたけど非連結な場合もある
  int t=0;
  int x=0;
  while(x!=-1){
    depth_search(V[x],t,Va,Vf);
    x=find_next_root(Va);
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << Va[i] << " " << Vf[i] << endl;
  }
}

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

void dfs(int cur);
int df[100][2]={};
bool dc[100]={};
bool adj[100][100]={};//初期化を忘れない
int n,u,v,k;
int t = 1;

int main(){
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
  
 
  dfs(0);
  
  for (int i=0; i<n; i++)
    cout << i+1 << " " << df[i][0] << " " << df[i][1] << endl;

}

void dfs(int cur){
  dc[cur] = true;
  df[cur][0] = t;
  t += 1;
  for (int i=0; i<n; i++){
    if (adj[cur][i] && !dc[i]){
      dfs(i);
    }
  }
  df[cur][1] = t; 
  t += 1;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;

const int max_v = 101;
vector<vector<int> > adj_list;
int d[max_v] = { 0 };
int f[max_v] = { 0 };
int discovered[max_v] = { 0 };
int t = 1;

// Depth-first Search ( Stack implementation)
void DFS(int v)
{
	stack<int> S;
	S.push(v);
	discovered[v] = 1;
	d[v] = t++;
	int i = 0;
	while (!S.empty()) {
		v = S.top();
		if (i < adj_list[v - 1].size()) {
			int u = adj_list[v - 1][i++];
			if (discovered[u] == 0) {
				discovered[u] = 1;
				d[u] = t++;
				S.push(u);
				i = 0;
			}
		}
		else {
			S.pop();
			f[v] = t++;
			i = 0;
		}
	}
}

int main(int argc, char** argv)
{
	// Input
	int n;
	int u, k;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		int v;
		vector<int> adj;
		for (int j = 0; j < k; j++) {
			cin >> v;
			adj.push_back(v);
		}
		adj_list.push_back(adj);
	}

	// Depth-first Search
	for (int i = 1; i <= n; i++) {
		if(discovered[i] == 0)
			DFS(i);
	}

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

	return 0;
}

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

# define WHITE 0
# define GREY  1
# define BLACK 2

int M[100][100];
int color[100], d[100], f[100];
int n, tt = 0;

void dfs_visit(int u) {
	color[u] = GREY;
	d[u] = ++tt;
	for (int 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() {
    for (int i = 0; i < n; i++) color[i] = WHITE;
	for (int i = 0; i < n; i++) {
	    if ( color[i] == WHITE ) dfs_visit(i);
	}
}

int main() {
    int u, v, k;
	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]++;
		}
	}
	dfs();
	for (u = 0; u < n; u++) {
	    printf("%d %d %d\n", u+1, d[u], f[u]);
	}
	return 0;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int main ()
{
    int N;
    cin >> N;

    int M[N][N];
    int D[N], F[N], C[N];

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    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--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}