Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

template<class T>
class DirectedGraph {
public:
	class Edge {
	public:
		int to;
		T cost;

		Edge(int t, T c) : to(t), cost(c) {}

		bool operator<(const Edge& right) const {
			return cost == right.cost ? to < right.to : cost < right.cost;
		}
	};

	vector<vector<Edge>> G;
	int V;

	DirectedGraph(int n = 0) {
		resize(n);
	}

	void resize(int n) {
		V = n;
		G.resize(n);
	}

	void addEdge(int from, int to, T cost = NULL) {
		int v = max(from, to);
		if (v >= V)
			resize(v + 1);
		G[from].push_back(Edge(to, cost));
	}


	int t = 1;
	vector<pii> stamp;
	vector<bool> visit;
	void dfs(int s) {
		visit.resize(V);
		stamp.resize(V);
		calcDfs(s);
	}

	void calcDfs(int s) {
		if (visit[s])
			return;

		stamp[s].first = t++;

		visit[s] = true;
		for (int i = 0; i < G[s].size(); ++i) {
			calcDfs(G[s][i].to);
		}

		stamp[s].second = t++;
	}

	vector<int> bfs() {

	}
};

int main() {
	DirectedGraph<int> g;
	int n, id, k, to;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		while (k--) {
			cin >> to;
			g.addEdge(id, to);
		}
	}

	for (int i = 1; i <= n; ++i)
		g.dfs(i);

	for (int i = 1; i <= n; ++i) {
		printf("%d %d %d\n", i, g.stamp[i].first, g.stamp[i].second);
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int M[N][N]={0};
int n;
int color[N]={WHITE},one[N],two[N];
int tt=0,aaa[N]={1};

int next(int num){
    for(int i=aaa[num];i<=n;i++){
        aaa[num]=i+1;
        if(M[num][i]) return i;
    }
    return -1;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    one[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                one[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            two[u]=++tt;
        }
    }
}

void dfs(){
    for(int i=1;i<=n;i++){
        if(color[i]==WHITE) dfs_visit(i);
    }
    for(int i=1;i<=n;i++){
        cout << i << " " << one[i] << " " << two[i] << endl;
    }
}




int main(void){
    cin >> n;
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v;
            cin >> v;
            M[u][v]=1;
        }
    }
    
    dfs();

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int t = 0;
int n;

void dfs_v(v2& a, v2& b, int p){
	p--;
	if(a.at(p).at(0) == -1){
		return;
	}
	b.at(p).push_back(++t);
	a.at(p).at(0) = -1;
	rep(i, a.at(p).at(1)){
		int np = a.at(p).at(2+i);
		dfs_v(a, b, np);
	}
	b.at(p).push_back(++t);
}
void dfs(v2& a, v2& b){
	rep(i, n){
		if(a[i][0] != -1){
			dfs_v(a, b, a[i][0]);
		}
	}
}

int main(){
	cin >> n;
	v2 a(n, v1(0));
	v2 b(n, v1(0));
	rep(i, n){
		int m;
		cin >>m;
		a[i].push_back(m);
		b[i].push_back(m);
		int x;
		cin >> x;
		a.at(i).push_back(x);
		rep(j, x){
			int y;
			cin >> y;
			a.at(i).push_back(y);
		}
	}
	dfs(a, b);
	rep(i, n){
		rep(j, 3){
			cout << b[i][j];
			if(j != 2) cout << " ";
			else cout << endl;
		}
	}
}

C++: #include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = (int)1e2 + 10;

int n;
vector<int> g[MAXN];
int vis[MAXN];
int st[MAXN],en[MAXN];
int clk;

void DFS(int u){
    vis[u]=1;
    st[u]=++clk;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(vis[v]) continue;
        DFS(v);
    }
    en[u]=++clk;
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int u,k; scanf("%d%d",&u,&k);
        while(k--){
            int v; scanf("%d",&v);
            g[u].push_back(v);
        }
        sort(g[u].begin(),g[u].end());
    }
    for(int i=1;i<=n;i++)if(!vis[i]) DFS(i);
    for(int i=1;i<=n;i++) printf("%d %d %d\n",i,st[i],en[i]);
}

int main(){
    work();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,lis[111][111]={},d[111]={},f[111],t=1;

void dfs(int now=1){
  d[now]=t++;
  for(int i=1;i<=n;i++)
    if(lis[now][i]&&d[i]==0)dfs(i);
  f[now]=t++;
}

int main(){
  cin>>n;
  for(int c=0;c<n;c++){
    int u,k,v;
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v;
      lis[u][v]=1;
    }
  }
  dfs();
  for(int i=1;i<=n;i++)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;  
  
  return 0;
}