Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll;
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x) low2way(v, x) - v.begin()       //1番左が0、もし見つから無いならｎを出力
#define higher(v, x) high2way(v, x) - v.begin() - 1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b) \
  putout(a);          \
  putout(b)
#define putout3(a, b, c) \
  putout(a);             \
  putout(b);             \
  putout(c)
#define putout4(a, b, c, d) \
  putout(a);                \
  putout(b);                \
  putout(c);                \
  putout(d)
#define putout5(a, b, c, d, e) \
  putout(a);                   \
  putout(b);                   \
  putout(c);                   \
  putout(d);                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}
ll lcm(ll x, ll y)
{
  ll z = gcd(x, y);
  return x * y / z;
}

ll primejudge(ll n)
{
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;
  double sqrtn = sqrt(n);
  Loop(i, 3, sqrtn + 1)
  {
    if (n % i == 0)
    {
      return 0;
    }
    i++;
  }
  return 1;
}

vector<bool> seen;
vec first;
vec last;
void dfs(const Graph &G, ll v, ll &time)
{
  if (!(seen[v]))
  {
    seen[v] = true;
    first[v] = time++;
    for (auto next_v : G[v])
    {
      if (seen[next_v])
        continue;
      dfs(G, next_v, time);
    }
    last[v] = time++;
  }
}
int main()
{
  ll n;
  cin >> n;
  Graph G(n);
  loop(i, n)
  {
    ll u, k;
    cin >> u >> k;
    while (k--)
    {
      ll x;
      cin >> x;
      Gput(u - 1, x - 1);
    }
  }
  vec id(n);
  loop(i, n) id[i] = i + 1;
  seen.assign(n, false); // 全頂点を「未訪問」に初期化
  first.resize(n);
  last.resize(n);
  ll time = 1;
  loop(i, n) dfs(G, i, time);
  loop(i, n)
  {
    cout << id[i] << " " << first[i] << " " << last[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
vector<int> data[100];
pair<int, int> finds[100];

int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        cin >> temp;
        rep(j, temp)
        {
            int foo;
            cin >> foo;
            data[i].push_back(foo - 1);
        }
    }
    rep(i, 100)
    {
        finds[i].first = -1;
    }
    int hoge = 0;
    rep(i, n) if (finds[i].first == -1)
        hoge = finds[i].second = dfs(i, hoge);
    rep(i, n)
    {
        cout << i + 1 << " " << finds[i].first << " " << finds[i].second << endl;
    }
    return 0;
}

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

int n, tt;
int M[N][N], color[N], d[N], f[N], 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 {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


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

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

int main() {
	int k , u, 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 i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}