Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int n, u;
int k[101], b[101], d[101], f[101];
int a[101][101];
int t = 1;

void dfs(int v){
    d[v] = t;
    t++;
    b[v]++;
    for(int l=0; l<k[v]; l++){
        if(b[a[v][l]] == 0){
            dfs(a[v][l]);
        }
    }
    f[v] = t;
    t++;
}


int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u >> k[u];
        for(int j=0; j<k[u]; j++){
            cin >> a[u][j];
        }
    }
    for(int v=1; v<=n; v++){
        if(b[v] == 0){
            dfs(v);
        }
        cout << v << " " << d[v] << " " << f[v] << endl;
    }
    return 0;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-12 18:24:44
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-12 18:38:47
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e2+10;

int d[MAXN],f[MAXN],a[MAXN][MAXN],n,cnt,u,v,t,book[MAXN];

void dfs(int x)
{
	if(!d[x])	d[x] = ++cnt;
	for(int i = 1; i <= n; ++i)
	{
		if(a[x][i] && !book[i])
		{
			book[i] = 1;
			dfs(i);
			book[i] = 0;
		}
	}
	f[x] = ++cnt;
	return;
}

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		cin>>u>>t;
		for(int j = 0; j < t; ++j)
		{
			cin>>v;
			a[u][v] = 1;
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i)
	{
		cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
	}
	return 0;
}

C++: #include <iostream>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
        for (int i = 0; i < n; i++) {
            if (adj_matrix[v][i] != 0) {
                dfs(i, n);
            }
        }
        if (f[v] == 0) {
            f[v] = t;
            t++;
        }
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj_matrix[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        cin >> u;
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            adj_matrix[u-1][v-1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        dfs(i, n);
    }

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

    return 0;
}

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

vector<int> G[100];
pair<int, int> T[100];
const int Inf = 10000*100000+100;
int timer = 1;

int main() {
  void dfs(int cur);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int l = 0; l < k; l++) {
      int v;
      cin >> v;
      G[i].push_back(v - 1);
    }
    T[i] = make_pair(Inf, Inf);
  }
  for (int i = 0; i < n; i++) {
    if (T[i].first == Inf) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << T[i].first << " " << T[i].second << endl;
  }
}

void dfs(int cur) { // cur を訪問
  // cur の訪問時刻を記録
  T[cur].first = timer;
  timer += 1;
  // 動作確認用表示
  for (int dst : G[cur]) { // 全ての節点 dst について
    if (T[dst].first == Inf)
    { // cur から dst に辺があり，dst を未訪問なら
      dfs(dst);
    }
  }
  T[cur].second = timer;
  timer += 1;
}

C++: #include <cstdio>

typedef struct timestamp {
        int d, f;
} timestamp;

const int N = 100;
bool graph[N][N];
timestamp ts[N];
int time = 0;

void search(int n, int cur) {
        if (ts[cur].d) {
                return;
        }
        ts[cur].d = ++time;
        for (int i = 0; i < n; i++) {
                if (graph[cur][i]) {
                        search(n, i);
                }
        }
        ts[cur].f = ++time;
}

int main() {
        int n, u, k, v;
        for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                        graph[i][j] = false;
                }
        }
        for (int i = 0; i < N; i++) {
                ts[i].d = ts[i].f = 0;
        }

        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                scanf("%d %d", &u, &k);
                if (!k) {
                        continue;
                }
                for (int j = 0; j < k; j++) {
                        scanf("%d", &v);
                        graph[u-1][v-1] = true;
                }
        }
        int cur = 0;
        search(n, cur);
        for (int i = 0; i < n; i++) {
                printf("%d %d %d\n", i+1, ts[i].d, ts[i].f);
        }

        return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int a[100],d[100],f[100];
int inf=100000,t=0,n;
int v[100][100];
void dfs(int s){
    d[s]=t++;
    a[s]=inf;
    for(int i=0;i<n;i++){
        if(v[s][i]==1&&a[i]!=inf){
            //cout<<s<<" "<<i<<endl;
            dfs(i);
        }
    }
    f[s]=t++;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int tmp;
      cin>>tmp;
      v[u-1][tmp-1]=1;
    }
  }
  dfs(0);
  for(int i=0;i<n;i++)
      if(!a[i])dfs(i);
  for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]+1<<" "<<f[i]+1<<endl;
  }
}

C++: #define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 100
//#define MAX_ 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = 0, f = 0;
};
Graph G[MAX];
int cou = 1;
void Depth(Graph *g)
{
	if (g->k >= 0) {
		if (g->d)
			return; 
		
		g->d = cou;
		++cou;
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			Depth(&G[*i]);
		}
		g->f = cou;
		++cou;
		
	}
}

int main(void)
{
	int n, u, xk, v;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &u, &xk);
		G[u - 1].id = u - 1;
		G[u - 1].k = xk;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &v);
			G[u - 1].node.push_back(v - 1);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (G[i].d == 0 && G[i].f == 0) 
			Depth(&G[i]);
		
	}
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", G[i].id + 1, G[i].d, G[i].f);
	}
}