Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

vector<int> V[100];//0 origin
bool complete[100] = {};
stack<int> S;
int time_ = 1;
int NodeStump[100][2];//find,end

void DFS(){
    NodeStump[S.top()][0] = time_;
    time_++;//d++
    if (S.empty()) return;
    
    REP1(i,V[S.top()].size()){
        if (!complete[V[S.top()][i]]){
            S.push(V[S.top()][i]);
            DFS();
        }
    }
    
    complete[S.top()] = true;
    NodeStump[S.top()][1] = time_;
    S.pop();
    time_++;//d--
}

int main(){
    INT(N);
    
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to - 1);
        }
    }
    
    S.push(0);
    
    DFS();
    
    REP1(i,N){
        printf("%d %d %d\n",i+1,NodeStump[i][0],NodeStump[i][1]);
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int d[100];
int f[100];
int G[100][100];
int now_time = 1;

void input_graph(int n) {
    int u, k, v;
    rep(i, n) {
        scanf("%d %d", &u, &k);
        u--;
        rep(j, k) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }
}

void dfs(int s, int n) {
    rep(i, n) {
        if(d[i] == -1 && G[s][i] == 1) {
            d[i] = now_time++;
            dfs(i, n);
        }
    }
    f[s] = now_time++;
}

void init(int n) {
    rep(i, n) { d[i] = -1; }
}

void print_graph(int n) {
    rep(i, n) { printf("%d %d %d\n", i + 1, d[i], f[i]); }
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    init(n);
    input_graph(n);
    rep(i, n) {
        if(d[i] == -1) {
            d[i] = now_time++;
            dfs(i, n);
        }
    }
    print_graph(n);
}

C++: //============================================================================
// Name        : Graph.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Node{
	int id;
	vector<int> adjNodes;
	bool isFound;
	int discover_time;
	int finish_time;
};

class Graph{
public:
	vector<Node> nodeList;
	Graph():nodeList(){}

	void insert(Node& i){
		nodeList.push_back(i);
	}

	void SearchDepthFirst(int source_id, int& timer){
		Node& source_node = nodeList.at(source_id);
		source_node.isFound = true;
		source_node.discover_time = timer;
		for(int i=0; i<source_node.adjNodes.size(); i++){
			if(nodeList.at(source_node.adjNodes.at(i)).isFound == false){
				timer ++;
				nodeList.at(source_node.adjNodes.at(i)).isFound = true;
				nodeList.at(source_node.adjNodes.at(i)).discover_time = timer;
				SearchDepthFirst(source_node.adjNodes.at(i), timer);
				nodeList.at(source_node.adjNodes.at(i)).finish_time = timer;
			}
		}
		timer++;

		source_node.finish_time = timer;
	}

	void SearchDepthFirstAll(int& timer){
		for(int i=0; i<nodeList.size(); i++){
			if(nodeList.at(i).isFound == false){
				SearchDepthFirst(i, timer);
				timer++;
			}
		}
	}

	void writeSearchResult(){
		for(int i=0; i<nodeList.size(); i++){
			cout << nodeList.at(i).id+1 << " " << nodeList.at(i).discover_time << " " << nodeList.at(i).finish_time << "\n";
		}
	}


	void write(){
		for(int i=0; i<nodeList.size(); i++){
			Node& node = nodeList.at(i);
			cout << node.id << " " << node.adjNodes.size() << " ";

			for(int j=0; j<node.adjNodes.size(); j++){
				cout << node.adjNodes.at(j) << " ";
			}
			cout << "\n";
		}

	}
};

void writeMatrix(vector<vector<int> > matrix){
	for(int i=0; i<matrix.size(); i++){
		for(int j=0; j<matrix.at(i).size()-1; j++){
			cout << matrix.at(i).at(j) << " ";
		}
		cout << matrix.at(i).at(matrix.at(i).size()-1);
		cout << "\n";
	}
}

int main() {
	int n;
	cin >> n;
	Graph g;

	for(int i=0; i<n; i++){
		int id, k;
		cin >> id >> k;
		vector<int> adjNodes;
		for(int j=0; j<k; j++){
			int input;
			cin >> input;
			adjNodes.push_back(input-1);
		}
		sort(adjNodes.begin(), adjNodes.end());
		Node node = {id-1, adjNodes, false, -1, -1};
		g.insert(node);
	}

	//g.write();
	int timer = 1;
	g.SearchDepthFirstAll(timer);
	g.writeSearchResult();

	return 0;
}