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 <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

  for(int i=1;i<=n;i++){
    printf("%d %d %d", v[i].id, v[i].d, v[i].f);
    if(i != n)printf("\n");
  }
  return 0;
}

C++: #include<iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt;
 
    for(v=0; v<n; v++){
        if(M[u][v]==0){continue;}
        if(color[v]==WHITE){dfs_visit(v);}
    }
    color[u]=BLACK;
    f[u]=++tt;
}

void dfs(){
    int u;
 
    for(u=0; u<n; u++){
        color[u]=WHITE;
    }
    tt=0;
    for(u=0; u<n; u++){
        if(color[u]==WHITE){dfs_visit(u);}
    }
    for(u=0; u<n; u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

int main(){
    int i,j,k,u,v;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j]=0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    dfs();
    return 0;
}

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

int n,v,u,k,Time,data[101][101],d[101],f[101];

//dfs
void visit(int u){
  int v;
  d[u] = Time++;
 
  for(v = 1; v <= n; v++){
    if(data[u][v]&d[v]==0)
      visit(v);
  }
  f[u] = Time++;
}
 
int main(){
  cin >> n;
  
  //初期化
  Time = 1;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      data[i][j]=0;
      d[j]=0;
      f[j]=0;
    }
  }
  
  //入力
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      data[u][v]=1;
    }
  }
  
  //dfs
  for(int i = 1;i <= n; i++){
    if(d[i]==0)visit(i);
  }
  
  //出力
  for(int i = 1;i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  
  return 0;
}

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

#define MAX 100
#define FND -1
#define CMP -2

int n, G_list[MAX+1];
int G[MAX+1][MAX+1];
int d[MAX+1][3];

void make_graph(void){
  scanf("%d", &n);

  for(int i=0; i<n; i++){
    int cnt, num, m;

    scanf("%d %d", &num, &cnt);
    G_list[i]=num;

    for(int j=0; j<cnt; j++){
      scanf("%d", &m);
      G[num][m]=1;
    }
  }
}

void check_depth(int data){
  stack<int> S;
  static int tm=0;
  
  S.push(data);
  d[data][0]=++tm;
  d[data][2]=FND;
  
  while(!S.empty()){
    int top=S.top();
    int next=-5;

    for(int i=0; i<n; i++){
      if(G[top][G_list[i]] == 1 && d[G_list[i]][2] == 0){
	next=G_list[i];
	S.push(next);
	d[next][2]=FND;
	d[next][0]=++tm;
	break;
      }
    }

    if(next == -5){
      d[S.top()][2]=CMP;
      d[S.top()][1]=++tm;
      S.pop();
    }

  }
}

void set_depth(void){

  for(int i=0; i<n; i++){
    if(d[G_list[i]][2] == 0) check_depth(G_list[i]);
  }
}

void print(void){

  for(int i=0; i<n; i++){
    printf("%d %d %d\n", G_list[i], d[G_list[i]][0], d[G_list[i]][1]);
  }
}

int main(void){

  make_graph();
  set_depth();
  print();
  
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
using namespace std;

int t = 1;
int first[101] = {0};
int last[101] = {0};
void dfs(vector<vector<int> > &graph, int v, set<int> &seen){
	seen.insert(v);
	first[v] = t;
	t++;
	for (int i=0;i<graph[v].size();i++){
		int nxt = graph[v][i];
		if (seen.count(nxt)) continue;
		dfs(graph, nxt, seen);
	}
	last[v] = t;
	t++;
}



int main(){
	int n; cin >> n;
	vector<vector<int> > graph(n+1);
	for (int i = 0; i < n; i++){
		int v, k; cin >> v >> k;
		for (int j = 0; j < k; j++) {
			int in; cin >> in;
			graph[v].push_back(in);
		}
	}

	set<int> seen;
	for (int i=1;i<n+1;i++){
		if (seen.count(i)) continue;
		dfs(graph,i,seen);
	}


	for (int i=1;i<n+1;i++){
		cout << i << " " << first[i] << " " << last[i] << endl;
	}

	return 0;
}