Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

int set_time = 1;
const int maxint = 1000;
struct timestamp;
vector<int> color;
vector<timestamp> ts;
vector< vector<int> > connective;

struct timestamp
{
    int node;
    int discoverry_time;
    int terminate_time;
};

void init_ts(int n, timestamp *a)
{
    a->node = n;
    a->discoverry_time = -1;
    a->terminate_time = -1;
}

void disp_ts(timestamp a)
{
    cout << a.node + 1 << " " << a.discoverry_time << " " << a.terminate_time << endl;
}

void dfs(int x, timestamp *a, vector<int> v)
{
    color[x] = 1;
    a->discoverry_time = set_time;
    set_time++;
    for (auto itr = v.begin(); itr != v.end(); itr++)
    {   
        if (color[*itr] == -1)
            dfs(*itr, &ts[*itr], connective[*itr]);
    }

    a->terminate_time = set_time;
    set_time++;
    
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, v, k, x;
    cin >> n;
    timestamp tsi;
    connective.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v >> k;
        color.push_back(-1);
        init_ts(i, &tsi);
        ts.push_back(tsi);
        for (int j = 0; j < k; j++)
        {
            cin >> x;
            connective[i].push_back(x-1);
        }
        
    }
    for (int i = 0; i < n; i++){
        if (color[i] == -1)
            dfs(i, &ts[i], connective[i]);
    }

    for_each(ts.begin(), ts.end(), disp_ts);

    return 0;
}


// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)

C++: #include <bits/stdc++.h>
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();
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int n = 0;
int u = 0;
int k[100];
int v[100][100];
int Discover[100] = { 0 };
int End[100] = { 0 };
//int nx = 0;
int p = 0;
void dfs(int l) {
	int i;
	int j;
	if (!Discover[l]) {
		Discover[l] = ++p;

		for (i = 0; i < n + 1; i++) {
			if (v[l][i]) {
				dfs(v[l][i]);
			}
		}
		End[l] = ++p;
	}
}
int main()
{
	int i;
	int j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u ;
		cin >> k[u];
		for (j = 0; j < k[u]; j++) {
			cin >> v[u][j];
		}
	}
	for (i = 1; i < n + 1; i++) {
		if (!Discover[i]) {
			dfs(i);
		}
	}
	for (i = 1; i < n + 1; i++) {
		cout << i << " " << Discover[i] << " " << End[i] << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std; 
struct TIMECOUNT {
	int d, f;
};
int main()
{
	int n, u, k, vv, time = 0;
	cin >> n;
	vector<TIMECOUNT> timecount(n);
	for (int variable = 0; variable < n; ++variable) {
		timecount[variable].d = 0;
		timecount[variable].f = 0;
	}
	vector<int> a;
	vector< vector<int> > v(n);
	for (int variable1 = 0; variable1 < n; ++variable1) {
		cin >> u >> k;
		for (int variable2=0; variable2 < k; ++variable2) {
			cin >> vv;
			v[variable1].push_back(vv);	
		}
		sort(v[variable1].begin(), v[variable1].end());
	}
	a.push_back(1);
	while (timecount[0].f == 0) {
		while (v[a.back() - 1].size() != 0) {
			++time;
			timecount[a.back() - 1].d = time;
			for (int variable = 0; variable < v[a.back() - 1].size(); ++variable) {
				if (timecount[v[a.back() - 1][variable] - 1].d == 0)
					a.push_back(v[a.back() - 1][variable]);
				else
					break;
			}
		}
		while (v[a.back() - 1].size() == 0) {
			++time;
			timecount[a.back() - 1].f = time;
			a.pop_back();
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << timecount[i].d << " " << timecount[i].f << endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

C++: #include <stdio.h>
 #define GRAY 1
#define WHITE 0
#define BLACK 2
 
int de[101], f[101], col[101];
int A[101][101];
int n, time;
 
void visit(int u) {
  int v;
   col[u] = GRAY;
   de[u] = ++time;
 
  for (v = 1; v <= n; v++) {
    if (col[v] == WHITE && A[u][v] == 1) visit(v);
  }
  col[u] = BLACK;
  f[u] = ++time;
}
 
void dfs() {
  int u;
  for (u = 1; u <= n; u++) {
    col[u] = WHITE;
  }
  time = 0;
  for (u = 1; u <= n; u++) {
    if (col[u] == WHITE) {
      visit(u);
    }
  }
}
 
int main() {
  int i, j, u, k, v;
 
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }
 
  dfs();
  for (i = 1; i <= n; i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
 
 
  return 0;
}