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<cstdio>
#include<cstdlib>
#include<string.h>
#include<stack>
using namespace std;

int n;
int m[100][100], d[100], f[100];
int t = 0;
char c[100];
stack<int> s;

int next(int u){
  for(int i = 0; i < n; i++){
    if(m[u][i] == 1 && c[i] == 'w') return i;
  }
  return 0;
}

void dfs(int u){
  s.push(u);
  c[u] = 'g';
  d[u] = ++t;

  while(s.empty() == 0){
    u = s.top();
    int v = next(u);
    if(c[v] == 'w'){
      c[v] = 'g';
      d[v] = ++t;
      s.push(v);
    }
    else{
      s.pop();
      c[u] = 'b';
      f[u] = ++t;
    }
  }
}


int main(){

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      m[i][j] = 0;
      c[i] = 'w';
    }
  }

  for(int i = 0; i < n; i++){
    int id, k, x;
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> x;
      m[i][x - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    if(c[i] != 'b') dfs(i);
  }

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

  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long i64;typedef vector<int> ivec;typedef vector<string> svec;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	color[u]=GRAY;
	d[u]=++tt;
	for(int v = 0;v<n;v++){
		if(M[u][v]==0) continue;
		if(color[v]==WHITE){
			dfs_visit(v);
		}
	}
	color[u]=BLACK;
	f[u]=++tt;
}

void dfs(){
	for(int u=0;u<n;u++) color[u] = WHITE;
	tt=0;
	for(int u=0;u<n;u++) if(color[u]==WHITE) dfs_visit(u);
	for(int u =0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(){
	int u,v,k;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(int j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

typedef vector<vector<int>> Graph;

int N;
Graph G;
vector<int> td, tf;
int timestamp;

void dfs(int v){
	td[v] = timestamp++;

	for(int i=0; i<G[v].size(); i++){
		int u = G[v][i];
		if(td[u] == -1){
			dfs(u);
		}
	}

	tf[v] = timestamp++;
}

int main(){
	cin >> N;
	G.resize(N);
	td.resize(N, -1);
	tf.resize(N, -1);

	for(int i=0; i<N; i++){
		int x; cin >> x; x--;
		int k; cin >> k;
		for(int i=0; i<k; i++){
			int y; cin >> y; y--;
			G[x].push_back(y);
		}
	}

	timestamp = 1;

	for(int i=0; i<N; i++) if(td[i] == -1)
		dfs(i);

	for(int i=0; i<N; i++){
		cout << i+1 << " " << td[i] << " " << tf[i] << endl;
	}

	return 0;
}

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

vector<vector< int> > tstamp;
int n;
vector<vector<int> > G;
int ttime=0;

void tansaku(int i){
  ttime++;
  if (!tstamp[i][0]) tstamp[i][0] = ttime;
  for (int j=0;j<n;j++)
    if(G[i][j]) tansaku(j);
  tstamp[i][1] = ++ttime;
}




int main(){
  cin >> n;
  G.assign(n, vector<int>(n,0));
  for (int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for (int j=0;j<k;j++){
      int v;
      cin >> v;
      G[u-1][v-1] = 1;
    }
  }
  tstamp.assign(n,vector<int>(2,0));
  tansaku(0);

  for(int id=0;id<n;id++){
    cout << id+1 << " " << tstamp[id][0] << " " << tstamp[id][1] << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力

vector<vector<ll> > G;
vector<bool> seen;
vector<ll> d;
vector<ll> f;
ll cnt=1;
//ll fcnt=1;
void dfs(ll v){
    seen[v] = 1;
    d[v] = cnt;
    cnt++;
    rep(i,G[v].size()){
        if(seen[G[v][i]] == 0){
            dfs(G[v][i]);
        }
    }
    f[v] = cnt;
    cnt++;
}

int main() {
    ll n;
    cin >> n;
    G.resize(n);
    seen.resize(n);
    d.resize(n);
    f.resize(n);

    rep(i,n){
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll v;
            cin>>v;
            G[i].pb(v-1);
        }
    }
    rep(i,n){
        if(seen[i]==0)
            dfs(i);
    }

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


    return 0;
    

}