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<iostream>
#include<stack>

using namespace std;

int  n, M[100][100], d[100], f[100], color[100], tt, nt[100], W = 0, G = 1, B = 2;

int next (int u) {

    int v;
    for (v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v] != 0) {
            return v;
        }
    }
    return -1;

}

void dfs_visit (int r) {

    int i, u, v;

    for (i = 0; i < n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = G;
    d[r] = ++tt;

    while (!S.empty()) {
        u = S.top();
        v = next (u);
        if (v != -1) {
            if (color[v] == W) {
                color[v] = G;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = B;
            f[u] = ++tt;
        }
    }

}

void dfs () {

    int i, u;

    for (i = 0; i < n; i++) {
        color[i] = W;
        nt[i] = 0;
    }
    time = 0;

    for (u = 0; u < n; u++) {
        if (color[u] == W) {
            dfs_visit(u);
        }
    }

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

}

int main () {

    int u, k, v, i, j;

    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs ();

    return 0;

}

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

#define MAX 105

struct Point{
    int id;
    int d;
    int f;
    bool flag;
    std::vector<int> child;
};

int stack[MAX];
int sp = 0;
int count = 1;

Point p[MAX];

void push(int id){
    if(p[id].flag == false){
        stack[sp++] = id;
        p[id].d = count++;
        p[id].flag = true;
    }
}

void pop(){
    p[stack[--sp]].f = count++;
    //return stack[sp];
}

void dft(int id){
    //std::cout << id << "に対しdft\n";
    push(id);
    int size = p[id].child.size();
    for(int i=0;i<size;i++){
        if(p[p[id].child[i]].flag == false){
            dft(p[id].child[i]);
        }
    }
    pop();
}

int main(){
    int n;
    int size;
    std::cin >> n;
    for(int i=1;i<=n;i++){
        std::cin >> p[i].id >> size;
        for(int j=0;j<size;j++){
            int tmp;
            std::cin >> tmp;
            p[i].child.push_back(tmp);
        }
    }
    for(int i=1;i<=n;i++){
        if(p[i].flag == false){
            dft(i);
        }
    }
    
    for(int i=1;i<=n;i++){
        std::cout << p[i].id << ' ' << p[i].d << ' ' << p[i].f << '\n';
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
vint G[100];
int FLG[100];
int D[100];
int F[100];
const int NIL = -1;
int tt;

void dfs(int ii){

	tt++;
	D[ii] = tt;

	// cout << "reach " << ii << " " << tt << endl;

	rep(i, G[ii].size()){
		int to = G[ii][i];
		if (D[to] == NIL){
			dfs(to);
		}
	}

	tt++;
	F[ii] = tt;
	// cout << "back " << ii << " " << tt << endl;

}

void run_dfs(){
	rep(i, N){ D[i] = NIL; }
	int start = 0;
	tt = 0;
	rep(i, N){
		if (D[i] == NIL) dfs(i);
	}
}

int main() {

	cin >> N;
	rep(i, N){
		int id, n; cin >> id >> n; id--;
		rep(j, n){
			int id_to; cin >> id_to; id_to--;
			G[id].push_back(id_to);
		}
	}

	run_dfs();

	rep(i, N){
		cout << i << " " << D[i] << " " << F[i] << endl;
	}
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> d[120];
bool visit[120];
int cnt = 0;
int fin[120];
int st[120];
void dfs(int p){
	cnt++;
	st[p]=cnt;
	//cout <<"p = "<<p<<" cnt = "<<cnt<<endl;
	visit[p]=true;
	for(int i =0;i <d[p].size();i++){
		if(!visit[d[p][i]]){
			dfs(d[p][i]);
		}
	}
	cnt++;
	fin[p]=cnt;

}
int main(){
	int n;
	cin>>n;
	memset(visit, false, sizeof(visit));
	for(int i =0;i < n;i++){
		int u,k;
		cin>>u>>k;
		for(int j =0;j < k;j++){
			int c;
			cin>>c;
			d[u].push_back(c);
		}
	}
	dfs(1);
	for(int i =1;i <=n;i++){
		cout <<i<<" "<<st[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector <int> m[103];
int kakunin[103]={0};
int d[103];
int f[103];
int cnt=1;
void dfs(int num){
    d[num]=cnt++;
    for(int i=0;i<m[num].size();i++){
        if(kakunin[m[num][i]]==0){kakunin[m[num][i]]=1;dfs(m[num][i]);}}
    f[num]=cnt++;
}
int main() {
    int n,a,tmp,id;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id;
        cin>>a;
        for(int j=0;j<a;j++){
            scanf("%d",&tmp);
            m[id].push_back(tmp);
        }
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i];}
}