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 <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

const int N = 100;
int n;
int d[N+1], f[N+1], state[N+1], ns[N+1][N+1];
stack<int> s;

int next(int u) {
  FOR(i, 1, n+1) {
    if (ns[u][i] == 1 && state[i] == 0) return i;
  }
  return -1;
}
int main() {
	cin.tie(0);
 	ios::sync_with_stdio(false);

  cin >> n;

  FOR(i, 1, n+1) state[i] = 0;
  FOR(i, 1, n+1) {
    FOR(j, 1, n+1) {
      ns[i][j] = 0;
    }
  }

  REP(i, n) {
    int p, m;
    cin >> p; cin >> m;

    REP(j, m) {
      int pp; cin >> pp;
      ns[p][pp] = 1;
    }
  }

  int t = 1;

  s.push(1);
  state[1] = 1;
  d[1] = 1;
  while (!s.empty()) {
    t++;

    int p, np;
    p = s.top();
    if ((np = next(p)) != -1) {
      s.push(np);
      state[np] = 1;
      d[np] = t;
    } else {
      s.pop();
      state[p] = 2;
      f[p] = t;
    }
  }

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

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

#define N 101

void DepthFirstSearch();

class stack{
public:
    int array[100];
    int top = -1;
    
    void push(int v) {
        top++;
        array[top] = v;
        return;
    }
    
    int pop() {
        top--;
        return array[top+1];
    }
    
    int show() {
        return array[top];
    }
};

typedef struct {
    int d;
    int f;
} P;

int n;
int t = 0;
int a[N][N] = {};
stack s;
P list[N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    
    int u, k, v;
    for(int i = 0; i < n; i++) {
        cin>>u>>k;
        
        for(int j = 0; j < k; j++) {
            cin>>v;
            a[u][v] = 1;
        }
    }
    
    for(int i = 1; i <= n; i++) {
        if(list[i].d == 0) {
            s.push(i);
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    
    for(int i = 1; i <= n; i++) {
        cout<<i<<' '<<list[i].d<<' '<<list[i].f<<endl;
    }
    
    return 0;
}

void DepthFirstSearch() {
    t++;
    int u = s.show();
    list[u].d = t;
    for(int i = 1; i <= n; i++) {
        if( a[u][i] == 1 ) {
            s.push(i);
            a[u][i] = 0;
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    t++;
    list[u].f = t;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}
int n,t=0;
vvi a;
vi d;
vi f;

void Depth(int pos) {
	if (d[pos] == 0) {
		d[pos] = ++t;
	}
	rep(i, n) {
		if (a[pos][i] == 1) {
			Depth(i);
		}
	}
	if (f[pos] == 0) {
		f[pos] = ++t;
	}
}


int main() {
	cin >> n;
	a.resize(n, vi(n, 0));
	d.resize(n, 0);
	f.resize(n, 0);
	rep(i, n) {
		int num,m;
		cin >>num >>m;
		rep(i, m) {
			int tmp;
			cin >> tmp;
			a[num - 1][tmp - 1] = 1;
		}
	}
	Depth(0);
	rep(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

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

using namespace std;

void dfs(int v,vector<vector<int>>& vertex, int d[], int f[]);

int cnt = 1;

int main(){
    int n;
    cin >> n;
    int num;
    int tmp2;
    int d[n] = {};
    int f[n] = {};
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2-1);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    dfs(0, vertex, d, f);
    for(int i=0;i<n;i++){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " <<  d[i] << " " << f[i] << endl;
    }
    return 0;
}

void dfs(int v, vector<vector<int>>& vertex, int d[], int f[]){
    d[v] = cnt++;
    for(int i : vertex[v]){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    f[v] = cnt++;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
#define MAX 100000

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;
int nt[N];

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

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

void dfs(){
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    nt[i]=0;
  }
  tt=0;

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

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

  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;
    }
  }
  dfs();
  return 0;
}