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 <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define MAXN 100
int n, timecount = 1;
int ans[MAXN][MAXN];
int d[MAXN], f[MAXN]; // d[i]はdを最初に発見した時刻,f[i]は調べ終わった時刻

int dfs(int p);

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = -1;
        f[i] = -1;
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans[i][j] = 0;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int tmp;
            cin >> tmp;
            ans[u-1][tmp-1] = 1;
        }
    }
//    for (int i = 0; i < n; i++) {
//        for (int j = 0; j < n; j++) {
//            if (j == n-1) cout << ans[i][j];
//            else cout << ans[i][j] << " ";
//        }
//        cout << endl;
//    }
    dfs(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

int dfs(int p)
{
    int ret = 0, count = 1;
    if (d[p] == -1) d[p] = timecount++;
    for (int i = 0; i < n; i++) {
        if (ans[p][i] == 1 && f[i] == -1) {
            dfs(i);
        }
    }
    if (f[p] == -1) f[p] = timecount;
    timecount++;
    return 0;
}

C++: #include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    deep(0);
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(105);
vector<bool> visited(105);
vector<int> d(105, -1);
vector<int> f(105);

int nowTime = 0;

int dfs(int s) {
	visited[s] = true;
	nowTime++;
	if (d[s] == -1) d[s] = nowTime;

	for(auto v: g[s]) {
		if (visited[v]) continue;
		dfs(v);
	}
	
	bool ok = true;
	for (auto v: g[s]) {
		if (visited[v]) continue;
		ok = false;
	}
	if (ok) f[s] = nowTime + 1;
	return nowTime++;
}


int main(void) {
	int n;
	cin >> n;
	rep (i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep (j, k) {
			int v;
			cin >> v;
			v--;
			g[u].pb(v);
		}
	}

	rep (i, n) if (!visited[i]) dfs(i);

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

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

static const int N = 100;
int n,color[N],M[N][N],d[N],f[N];
int t;

void dfs_visit(int u){
  int v;
  color[u] = 1;
  d[u] = ++t;
  for (v = 0; v < n; v++) {
    if(M[u][v] == 0) continue;
    if(color[v] == 0) dfs_visit(v);
  }
  color[u] = 2;
  f[u] = ++t;
}
void dfs(){
  int u;

  for (u = 0; u < n; u++) {
    color[u] = 0;
  }
  t = 0;

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

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

int main() {
  int i,j,u,k,v;

  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;
    }
  }
  //cout << "done1" << endl;

  dfs();

  return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<vector<int> > arr(n);
    vector<int> tmparr;
    int u, k;
    int tmp;
    for(int i=0;i<n;++i){
        cin>>u>>k;
        u--;
        tmparr.clear();
        for(int j=0;j<k;++j){
            cin>>tmp;
            tmp--;
            tmparr.push_back(tmp);
        }
        arr[u] = tmparr;
    }
    stack<int> stack;
    stack.push(0);
    map<int, int> used;
    map<int, int> owari;
    map<int, pair<int, int> > ans;
    int state;
    int time = 1;
    while(!stack.empty()){
        while(!stack.empty()){
            state = stack.top();
            if(used[state]>0){
                if(owari[state]==0){
                    ans[state].second = time;
                    owari[state]++;
                    time++;
                }
                stack.pop();
            }
            else {
                ans[state].first = time;
                time++;
            }
            used[state]++;
            for(int i=arr[state].size()-1;i>=0;--i){
                if(used[arr[state][i]]==0){
                    stack.push(arr[state][i]);
                }
            }
        }
        for(int i=0;i<n;++i){
            if(used[i]==0){
                stack.push(i);
                break;
            }
        }
    }
    for(int i=0;i<n;++i){
        cout<<i+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}