Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include "stdafx.h"

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <functional>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using pci = pair<char, int>;
using vpci = vector<pci>;
using vb = vector<bool>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(int i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) { ll prime; double sqrtmax = sqrt(max); vector<ll> primeVec, searchVec; FOR(i, 2, max + 1) searchVec.push_back(i); do { prime = searchVec[0]; primeVec.push_back(prime); auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; }); searchVec.erase(itr, searchVec.end()); } while (prime < sqrtmax); primeVec.reserve(primeVec.size() + searchVec.size()); primeVec.insert(primeVec.end(), beginend(searchVec)); return primeVec; }
bool isPrime(ll x) { if (x == 2) return true; if (x < 2 || x % 2 == 0) return false; ll i = 3; while (i <= sqrt(x)) { if (x%i == 0) return false; i += 2; }return true; }
vi seq(int max, int start = 0) {vi rt(max - start+1);FOR(i, start, max+1) rt[i] = i;return rt;}
template<typename T> size_t find_first_of(vector<T> v, T val) { auto itrfind = find(beginend(v), val); size_t dis = distance(v.begin(), itrfind); if (dis == v.size()) { return -1; }return dis; }
template<class T> struct Identity {typedef T type;};
template<typename T> vector<T> select(const vector<T> &v, typename Identity<function<T(const T &)>>::type ft) {vector<T> rt; for (T item : v) { rt.push_back(ft(item)); }return rt;}
template<typename T> string join(const vector<T> &v, typename Identity<function<string(const T &)>>::type ft) {string rt = "";Foreach(x, v) {rt += ft(x);}return rt;}



int d[105]{ 0 }, f[105]{ 0 };
int _time = 1;
int N;
void dfs(vvi & box,int v) {
	if (d[v] != 0) return;
	d[v] = _time++;
	for (int i = 0; i < N; i++) if (box[v][i] != 0) {
		dfs(box,i);
	}
	f[v] = _time++;
	return;
}

int main(){
	cin >> N;
	vvi box(N, vector<int>(N, 0));
	REP(i, N) {
		int v, k, u;
		cin >> v >> k;
		REP(n, k) {
			cin >> u;
			box[i][u-1] = 1;
		}
	}
	dfs(box, 0);

	REP(i, N) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#include<string.h>
#define MAX 101
#define WHITE -1
#define GRAY 2
#define BLACK 1
using namespace std;

int G[MAX][MAX]={},d[MAX]={},f[MAX]={},color[MAX]={},times=0,Adj[MAX]={};

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

void visit(int u,int n){
    color[u]=GRAY;
    d[u]=++times;
    int v=1;
    while(v<=n){
        if(G[u][v]>0){
            if(color[v]==WHITE)visit(v,n);
        }
        v++;
    }
    color[u]=BLACK;
    f[u]=++times;
}

void dfs(int V[],int n){
    int u;
    for(u=1;u<=n;u++){
        color[u]=WHITE;
    }
    times =0;
    for(u=1;u<=n;u++){
        if(color[u]==WHITE)visit(u,n);
    }
}

int main(){
  int n,i,k,j,A,B,V[MAX]={};
  cin>>n;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
        G[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    cin>>A>>k;
    for(j=0;j<k;j++){
      cin>>B;
      G[A][B]=1;
    }
  }
  dfs(V,n);
  print(n);
}

C++: 
/*
Problem

Category
DFS

URL:
http://judge.u-aizu.ac.jp/onlinejudge/submission.jsp#submit/ALDS1_11_B

考察:


Date: 2020/04/14
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int n;
int counter = 1;
vector<vector<int>> ALL;
// vector<int> isVisited;
vector<int> d;
vector<int> f;
vector<int> visited;

/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>n;
    d.resize(n);
    f.resize(n);
    for(int i=0; i<n; ++i) {
        int u, k;
        cin>>u>>k;
        u--;
        vector<int> AL;
        for(int j=0; j<k; ++j) {
            int v;
            cin>>v;
            AL.push_back(--v);
        }
        ALL.push_back(AL);
    }
}

void dfs(int v) {    
    d[v] = counter++;
    visited.push_back(v);
    for(auto u: ALL[v]) {
        if (find(visited.begin(), visited.end(), u) == visited.end()) {
            dfs(u);
        }
    }
    f[v] = counter++;
}


void solve() {
    for(int u=0; u<n; ++u) {
        if (find(visited.begin(), visited.end(), u) == visited.end()) {
            dfs(u);
        }
    }
    for(int i=0; i<n; ++i ) {
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}