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 <vector>
#include <iostream>
using namespace std;
int n, u, k, v, t, d[100][2]; vector<int> g[100];
void rec(int pos) {
	for(int i = 0; i < g[pos].size(); i++) {
		if(!d[g[pos][i]][0]) {
			d[g[pos][i]][0] = ++t;
			rec(g[pos][i]);
			d[g[pos][i]][1] = ++t;
		}
	}
}
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) cin >> v, g[u - 1].push_back(v - 1);
	}
	for(int i = 0; i < n; i++) cout << i + 1 << ' ' << d[i][0] << ' ' << d[i][1] << endl;
}

C++: /*
AizuOJ ALDS1_11_B

???;DFS;????´¢;?¨????
*/
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN=110;
int n;
vector<int> adj[MAXN];
int visited[MAXN], d[MAXN], f[MAXN], t=0;

void dfs(int s) {
    visited[s]=true;
    d[s]=++t;
    for (vector<int>::iterator iter=adj[s].begin(); iter!=adj[s].end(); iter++) {
        if (!visited[*iter]) dfs(*iter);
    }
    f[s]=++t; // ????????¶????????????
}

void add_edge(int u, int v) {
    adj[u].push_back(v);
}

int k, tmp, v;
int main() {
    scanf("%d", &n);
    for (int u=1; u<=n; u++) {
        scanf("%d%d", &tmp, &k); // k ?????????
        while (k--) {
            scanf("%d", &v);
            add_edge(u, v);
        }
        sort(adj[u].begin(), adj[u].end());
    }
    for (int u=1; u<=n; u++) {
        if (!visited[u]) dfs(u);
    }
    for (int u=1; u<=n; u++) {
        printf("%d %d %d\n", u, d[u], f[u]);
    }
    return 0;
}

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


using namespace std;

int timecount = 0;

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap);

int main(){
  int u, i, id, k, j;
  cin >> u;
  unordered_map<int, vector<int> > mymap;

  for (i = 0; i < u; ++i){
    cin >> id >> k;
    vector<int> points;
    for (j = 0; j < k; ++j){
      int a;
      cin >> a;
      points.push_back(a);
    }
    mymap[id] = points;
  }
  
  bool visited[u+1];
  for (j = 1; j <= u; ++j){
    visited[j] = false;
  }
  visited[1] = true;

  int timearray[u+1];
  for (j = 1; j <= u; ++j){
    timearray[j] = 0;
  }
  int timearray_end[u+1];
  for (j = 1; j <= u; ++j){
    timearray_end[j] = 0;
  }

  dfs(1, u, visited, timearray, timearray_end, mymap);

  for (j = 1; j <= u; ++j){
    cout << j << " " << timearray[j] << " " << timearray_end[j]<< endl;
  }

}

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap){
  timecount++;
  timearray[cur] = timecount;

  for(int i = 1; i <= u; ++i){
    
    if((i!=cur)&&(find(mymap[cur].begin(), mymap[cur].end(), i) != mymap[cur].end())&&(!visited[i])){
      visited[i] = true;
      dfs(i, u, visited, timearray, timearray_end, mymap);
    }
  }
  timecount++;

  timearray_end[cur] = timecount;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int G[101][101];
int d[101];
int f[101];
bool checked[101];

void explore(int id, int n,int& t)
{
	if (checked[id])
	{
		return;
	}
	checked[id] = true;
	d[id] = t;
	t++;

	for (int i = 1; i <= n; i++)
	{
		if (G[id][i] == 1)
		{
			explore(i, n,t);
		}
	}

	f[id] = t;
	t++;
}

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

	for (int i = 0; i < n; i++)
	{
		int id, k;
		cin >> id >> k;

		for (int i = 0; i < k; i++)
		{
			int v;
			cin >> v;
			G[id][v] = 1;
		}
	}

	int t = 1;
	explore(1, n, t);

	for (int i = 1; i <= n; i++)
	{
		printf("%d %d %d\n", i, d[i], f[i]);
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int visit[111],d[111],f[111],t;
//    訪問状態 　　発見　　　完了
int n,M[111][111];
static const int WHITE=0; //未訪問
static const int GRAY=1; //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) dfs(i); //訪問してないか... iを始点に
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
  }
  return(0);
}

C++: #include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
const long long MAX = 1000;

ll n;
vllvll M(MAX,vll(0));
vll ts1(MAX);
vll ts2(MAX);
vll seen(MAX, 0);

void rec(ll node, ll& ptr)
{
    ts1[node] = ptr++;
    seen[node] = 1;
    for (ll adj : M[node]) {
        if (seen[adj] == 1) continue;
        rec(adj, ptr);
    }
    ts2[node] = ptr++;
}

void dfs()
{
    ll ptr = 1;
    rep(i, 0, n) {
        if (seen[i] == 0) {
            rec(i, ptr);
        }
    }
}

int main()
{
    cin >> n;
    ll u, k, v;
    rep(i, 0, n) {
        cin >> u >> k;
        --u;
        rep(j, 0, k) {
            cin >> v;
            --v;
            M[u].push_back(v);
        }
    }
    ll f = 0, l = 0;
    dfs();
    rep(i, 0, n) {
        cout << i+1 << ' ' << ts1[i] << ' ' << ts2[i]<< endl;
    }
}