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>
#include<stack>

using namespace std;

int  n, M[100][100], d[100], f[100], color[100], tt, nt[100], W = 0, G = 1, B = 2;

int next (int u) {

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

}

void dfs_visit (int r) {

    int i, u, v;

    for (i = 0; i < n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = G;
    d[r] = ++tt;

    while (!S.empty()) {
        u = S.top();
        v = next (u);
        if (v != -1) {
            if (color[v] == W) {
                color[v] = G;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = B;
            f[u] = ++tt;
        }
    }

}

void dfs () {

    int i, u;

    for (i = 0; i < n; i++) {
        color[i] = W;
        nt[i] = 0;
    }
    tt = 0;

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

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

}

int main () {

    int u, k, v, i, j;

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

    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;
const ll MOD = 998244353;

int t = 1, k[100], v[100][100], d[100], f[100];

void dfs(int x) {
    d[x] = t;
    t++;
    rep(i, k[x]) {
        int y = v[x][i];
        if (d[y] > 0) continue;
        dfs(y);
    }
    f[x] = t;
    t++;
}

int main() {
    int n, u;
    cin >> n;
    rep(i, n) {
        cin >> u;
        cin >> k[u - 1];
        rep(j, k[u - 1]) {
            cin >> v[u - 1][j];
            v[u - 1][j]--;
        }
    }
    rep(i, n) d[i] = 0;
    rep(i, n) if (d[i] == 0) dfs(i);
    rep(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
    }
}

C++: #include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 105;
const int INF = 1000;

vector<int> to[MAX_N];
int d[MAX_N], f[MAX_N]; // d：発見時刻、f：完了時刻
int t = 0; int n; 

void init(){
    rep(i,MAX_N){
        d[i] = INF, f[i] = INF;
    }
}

void dfs(int u){
    if(d[u] == INF) d[u] = ++t;
    for(auto v: to[u]){
        if(d[v] == INF) dfs(v); // *もう訪問が完了している頂点には不要に寄らない
    }
    if(f[u] == INF) f[u] = ++t;
}

void dfs_init(){
    rep(i,n){
        if(d[i] == INF) dfs(i);
    }
}

int main()
{
    cin >> n;
    init();
    rep(i,n){
        int u, k; cin >> u >> k; --u;
        rep(_,k){
            int v; cin >> v; --v;
            to[u].push_back(v);
        }
    }
    dfs_init();
    rep(i,n){
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}

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

using namespace std;

vector<int> F;
vector<int> L;
vector<bool> seen;

void dfs(vector<vector<int>> &G,int v,int &t){
    F[v]=t++;

    seen[v]=true;

    for(int i=0;i<G[v].size();i++){
        if(seen[G[v][i]])continue;
        dfs(G,G[v][i],t);
    }

    L[v] = t++; 
}

int main(){

    int n;
    cin >> n;

    vector<vector<int>> G(n);

    for(int i=0;i<n;i++){
        int a,k;
        cin >> a >> k;
        for(int j=0;j<k;j++){
            int b;
            cin >>b;
            G[i].push_back(b-1);
        }
    }

    seen.assign(n,false);
    F.resize(n);
    L.resize(n);
    int t=1;
    
    

    for(int i=0;i<n;i++){
        if(!seen[i])dfs(G,i,t);
        cout << i+1 << " " << F[i] << " " << L[i] << endl;
    }

    return 0;




}

C++: #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int cnt = 1; // time stamp
vector<int> seen, visited;

void dfs(vector<vector<int> > graph, int v) {
    if (seen[v] != 0) return;
    seen[v] = cnt;
    cnt++;
    for (int i = 0; i < graph[v].size(); i++) {
        dfs(graph, graph[v][i]);
    }
    visited[v] = cnt;
    cnt++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n+1);
    for (int i = 1; i <= n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            graph[u].push_back(v);
        }
    }
    seen.assign(n+1, 0);
    visited.assign(n+1, 0);
    for (int i = 1; i <= n; i++) dfs(graph, i);
    for (int i = 1; i <= n; i++) {
        cout << i << " " << seen[i] << " " << visited[i] << endl;
    }
}

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