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<string>
#include<stack>
#include<unordered_set>
#include<algorithm>

#define N 1000

int n, u, k, v;
int G[N][N];
std::stack<int> S;
std::unordered_set<int> hasVisited;
int count, d[N], f[N];

void visit(int x) {
    hasVisited.insert(x);
    d[x] = count++;
    for(int i = 1; i <= n; i++) {
        if(G[x][i] != 0 && hasVisited.find(i) == hasVisited.end()) {
            visit(i);
        }
    }
    f[x] = count++;
}

int main() {

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            G[i][j] = 0;
        }
    }
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::cin >> u >> k;
        for(int j = 0; j < k; j++) {
            std::cin >> v;
            G[u][v] = 1;
        }
    }

    count = 1;
    for(int i = 0 ; i < N; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for(int i = 1; i <= n; i++) {
        if(hasVisited.find(i) == hasVisited.end())
            visit(i);
    }
    for(int i = 1; i <= n; i++) {
        printf("%i %i %i\n", i, d[i], f[i]);
    }

    return 0;
}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << start[i] << " " << finish[i] << endl;
    }
}

C++: #include <bits/stdc++.h>

int d[128];
int f[128];
bool c[128][128];
int n;
int t;
int checked[128];

void dfs(int i) {
  if( checked[i] ) return;
  checked[i] = true;
  t += 1;
  d[i] = t;
  for(int k = 1; k <= n; ++k) {
    if( c[i][k] ) {
      dfs(k);
    }
  }
  t += 1;
  f[i] = t;
  return;
}

int main(void) {

  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      c[i][j] = false;
    }
  }

  std::cin >> n;

  int u, k, v;
  for(int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for(int j = 0; j < k; ++j) {
      std::cin >> v;
      c[u][v] = true;
    }
  }

  dfs(1);

  for(int i = 1; i <= n; ++i) {
    std::cout << i << " " << d[i] << " " << f[i] << std::endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define MAX 101
#define VISITED 0;
#define UNVISITED -1
#define NO_POSSIBLE_VERTICE -3


int d[MAX], f[MAX];
int timeStamp = 0;
vector<int> adj[MAX];
stack<int> S;

bool isAdjacentVerticeUnvisited(int currVertice, int i){
	if (f[adj[currVertice][i]] == UNVISITED) 
		return true;
	else
		return false;
}

int getNextPossibleVertice(int currVertice) {
	int i = 0;
		
	for (i = 0; i < adj[currVertice].size(); i++){
		if (isAdjacentVerticeUnvisited(currVertice, i)){
			return adj[currVertice][i];
		}
	}

	return NO_POSSIBLE_VERTICE;

}

void dfs() {

	while (!S.empty()) {
		int currVertice = S.top();

		int nextNode = getNextPossibleVertice(currVertice);

		// cout << "dfs " << currVertice << " nt:" << nextNode << "\n";

		if (nextNode == NO_POSSIBLE_VERTICE) {
			f[currVertice] = ++timeStamp;
			S.pop();
		} else {
			d[nextNode] = ++timeStamp;
			f[nextNode] = VISITED;
			S.push(nextNode);
		}
	}

}


int main() {
	int n, i, j, vertice, id, degree;
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> id;
		cin >> degree;
		for (j = 0; j < degree; j++) {
			cin >> vertice;
			if (id != vertice){
				adj[id].push_back(vertice);
			}
		}
	}
	// init
	for (i = 1; i <= n; i++) {
		f[i] = UNVISITED;
	}

	for (i = 1; i <= n; i++) {
		if (f[i] == UNVISITED) {
			S.push(i);
			d[i] = ++timeStamp;
			f[i] = VISITED;
			dfs();
		}
	} 
	

	// for (i = 1; i <= n; i++) {
	// 	for (j = 0; j < adj[i].size(); j++)
	// 		cout << " " << adj[i][j];
	// 	cout << "\n" << i <<" size : " << adj[i].size() << "\n";
	// }

	for (i = 1; i <= n; i++) 
		cout << i << " " << d[i] << " " << f[i] <<"\n";

}

C++: //
//  main.cpp
//  619
//
//  Created by 8595198919 on 14/06/16.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#define _2
#ifdef _1
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;

int dist[105];
queue<int> que;
vector<int> G[105];
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        dist[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    que.push(1);
    dist[1]=0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int d = dist[now];
        rep(i,G[now].size()){
            if(dist[G[now][i]]==-1){
                dist[G[now][i]]=d+1;
                que.push(G[now][i]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout <<i <<" " << dist[i]<<endl;
    }
}
#endif

#ifdef _2

#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

#endif