Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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;
}

C++: // J4180449 三宅亮輔
// 問題名
// - Depth First Search
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_11_B
// 所要時間
// - 35分
// 学んだこと
//  どこで時間を更新するのかの理解に苦しんだ
//  番号が小さい順に巡ることをソートで実装しようとしたが必要ないと気づいて楽になった
//  再帰関数のスマートさに感動した

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

typedef long long ll;

int n;

vector<int> v[100];
bool visited[100];
int d[100];
int f[100];

int dfs(int i, int now) {
    visited[i] = true;
    now++;
    d[i] = now;
    for(int j = 0; j < v[i].size(); j++) {
        if(!visited[v[i][j]])
            now = dfs(v[i][j], now);
    }
    now++;
    f[i] = now;
    return now;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            v[u].push_back(x);
        }
    }
    int now = 0;
    for(int i = 0; i < n; i++) {
        if(!visited[i])
            now = dfs(i, now);
    }

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