Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

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

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[now]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define W 0
#define B 1
#define G 2
#define rep(i,a) for(i=1;i<=a;i++)
using namespace std;

vector <vector<int> > A;
vector <int> c;
vector <int> d;
vector <int> f;
vector <int> k;

int n,u,t;

void visit(int r) {
    int i;
    c[r] = G;
    d[r] = ++t;
    rep(i,k[r]){
        if(c[A[r][i]] == W) visit(A[r][i]);
    }
    c[r] = B;
    f[r] = ++t;
}

void dfs(void){
    int i;
    rep(i,n) 
        c[i] = W;
    t = 0;
    rep(i,n){
        if(c[i] == W) visit(i);
    }
}

int main(void){
    int i,j;
    cin >> n;
    c.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);
    k.resize(n+1);
    A.resize(n+1);
    rep(i,n) A[i].resize(n+1);
    rep(i,n){
        cin >> u >> k[i];
        rep(j,k[i]){
            cin >> A[i][j];
        }
    }
    dfs();
    rep(i,n){
        cout << i << " " <<d[i] << " "<< f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int visited[100]={0};
int V[100][100]={0};
int start[100]={0};
int finish[100]={0};
int t=1;

void dfs(int i,int n){
  start[i]=t++;
  visited[i]++;
  for(int j=0;j<n;j++){
    if(V[i][j]==1 and visited[j]==0){
      dfs(j,n);
    }
  } 
  finish[i]=t++;
}



int main () {
    int n,k;
    int p1, p2;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            V[i][j] = 0;
        }
  }
  for(int i=0;i<n;i++){
    cin>>p1>>k;
    for(int j=0;j<k;j++){
      cin>>p2;
      V[p1-1][p2-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visited[i]==0){
      dfs(i,n);
    }
  }
  for(int i=0;i<n;i++){
      cout << i + 1 << " ";
      cout<<start[i] << " " << finish[i] << "\n";
  }


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1

// グラフの隣接頂点リスト表現
struct GraphAV{
    int p;  // 頂点数
    int q;  // 辺数
    // int AV[VMAX][DMAX]; 
    vector<vector<int>> AV;  // 隣接頂点リスト
};

GraphAV G;
// int d[VMAX],f[VMAX];
// bool seen[VMAX];
vector<int> d(VMAX);
vector<int> f(VMAX);
vector<bool> seen(VMAX);
int t=1;
void DFS(int v,int& t);

int main(){
    cin>>G.p;

    d.resize(G.p+1);
    f.resize(G.p+1);
    G.AV.resize(G.p+1);
    seen.resize(G.p+1);
    G.AV[0]={NOTUSED};
    d[0]=NOTUSED;
    
    for(int i=1; i<=G.p; i++){
        int u,k;
        cin>>u>>k;
        G.AV[u].resize(k);
        for(int j=0; j<k; j++){
            cin>>G.AV[u][j];
        }
    }

    for(int i=1; i<=G.p; i++){
        if(seen[i]){
            continue;
        }
        DFS(i,t);
    }

    for(int i=1; i<=G.p; i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

void DFS(int v,int& t){
    d[v]=t++;

    seen[v]=true;
    // v から行ける各頂点 adj_v について
    for(int adj_v:G.AV[v]){
        if(seen[adj_v]) continue; // adj_v が探索済なら何もしない
        DFS(adj_v,t);  // 再帰的に探索
    }

    f[v]=t++;
}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int>> G[101];

int ti = 1;

void dfs(int id) {
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0, l=adj.size(); i<l; ++i) {
		if ( ! d[adj[i]]) {
			dfs(adj[i]);
		}
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	dfs(1);

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