Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

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

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int f_stamp[103];
int e_stamp[103];
vector<vector<int> > edge;
int t;
void dfs(int v){
	f_stamp[v] = ++t;
	REP(i,edge[v].size()){
		if(not f_stamp[edge[v][i]]){
			dfs(edge[v][i]);
		}
	}
	e_stamp[v] = ++t;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	edge.resize(n,vector<int>());
	REP(i,n){
		int v;cin>>v;v--;int t;cin>>t;
		while(t--){
			int u;cin>>u;u--;
			edge[v].push_back(u);
		}
	}
	REP(i,n){
		if(not f_stamp[i]){
			dfs(i);
		}
	}
	REP(i,n){
		cout << i+1 << ' ' << f_stamp[i] << ' ' << e_stamp[i] << endl;
	}
  return 0;
}

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

int n, G[MAX][MAX], d[MAX], f[MAX], Mytime;

void dfs(int r) {
	int nt[n + 1], st[n + 1], i;
	for (i = 1; i <= n; i++) {
		nt[i] = 1;
		st[i] = 0;
	}
	stack<int> S;
	S.push(r);
	d[r] = ++Mytime;
	st[r] = 1;
	while (!S.empty()) {
		int u = S.top();
		int v;
		for (v = nt[u]; v <= n; v++) {
			nt[u] = v + 1;
			if (G[u][v] && st[v] == 0) 
				break;
		}
		if (v <= n) {
			d[v] = ++Mytime;
			st[v] = 1;
			S.push(v);
		} else {
			S.pop();
			f[u] = ++Mytime;
		}
	}
}

int main(void) {
	int i, j, u, k, v;
	for (i = 0; i < MAX; i++) {
		d[i] = 0;
		f[i] = 0;
		for (j = 0; j < MAX; j++) {
			G[i][j] = 0;
		}
	}
	Mytime = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	dfs(1);
	for (i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
}