Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>

using namespace std;
int n;
list<int> adj[101];
int d[101] = {};
int f[101] = {};

void DFS(int v)
{
    static int num = 1;
    d[v] = num++;
    while (!adj[v].empty())
    {
        if (d[adj[v].front()] == 0)
            DFS(adj[v].front());
        adj[v].pop_front();
    }
    f[v] = num++;
}

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

int main()
{
    int u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u].push_back(v);
            k--;
        }
    }

    DFS(1);

    print();

    return 0;
}

C++: /* 
 * ALDS1_11B.cpp
 */
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int N;
int ad_k[101];
int ad_list[101][101];

int jikan = 0;
int d[101], f[101];
bool visited[101];

void visit(int id) {
    if (visited[id])
        return;

    visited[id] = true;
    d[id] = ++jikan;
    for (int i = 0; i < ad_k[id]; ++i) {
        visit(ad_list[id][i]);
    }
    f[id] = ++jikan;
}

int main(void) {

    scanf("%d", &N);
    for (int i = 1, id; i <= N; ++i) {
        scanf("%d", &id);
        scanf("%d", ad_k + id);
        for (int j = 0; j < ad_k[id]; ++j) {
            scanf("%d", ad_list[id] + j);
        }
    }

    for (int i = 1; i <= N; ++i) {
        visit(i);
    }

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

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> PP;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[200];
int d[200] = {}, f[200] = {};

int func(int pos, int time){
  if(d[pos] > 0){
    return time;
  }
  d[pos] = time;
  time += 1;
  for(int to : E[pos]){
    time = func(to, time);
  }
  f[pos] = time;
  time += 1;
  return time;
}

int main(){
  int n;
  cin >> n;
  for(int loop = 0; loop < n; loop++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int v;
      cin >> v;
      E[u].push_back(v);
    }
  }
  int time = 1;
  for(int i = 1; i <= n; i++){
    if(d[i] == 0){
      time = func(i, time);
    }
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

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

using namespace std;

struct Edge
{
	int to;
};

vector<vector<int>> DFS(vector<vector<Edge>>& G)
{
	int timecounter = 0;
	int next = 1;
	vector<vector<int>> result;
	result = vector<vector<int>>(2, vector<int>(G.size(), 0));
	vector<int> prev(G.size(),0);
	
	while(result[1][0] == 0){
		int tmp;
		if(result[0][next - 1] == 0){
			timecounter += 1;	
			result[0][next - 1] = timecounter;
		}

		if(G[next - 1].empty()){
			if(result[1][next - 1] == 0){
				timecounter +=1;
				result[1][next - 1] = timecounter;
			}
			next = prev[next - 1];
		}else{
			tmp = G[next - 1].begin()->to;
			G[next - 1].erase(G[next - 1].begin());
			prev[tmp - 1] = next;
			next = tmp;
		}
	}
	return result;
}

int main(void)
{
	int n;
	cin >> n;

	vector<vector<Edge>> AdjList(n);
	for(int i = 0; i < n; i++){
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			AdjList[i].push_back(Edge{v});
		}
	}

	vector<vector<int>> timestump = DFS(AdjList);
	
	for(int i = 0; i < AdjList.size(); i++){
		cout << i + 1 << " " << timestump[0][i] << " " << timestump[1][i] << endl;
	}
	return 0;
}

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

#define MAX 101

using namespace std;

int visited[MAX],d[MAX],f[MAX];
int tt=0;
vector<int> G[MAX];

void dfs(int u){
  d[u]=++tt;
  for(int i=0;i<G[u].size();i++){
    if(visited[G[u][i]]==0) dfs(G[u][i]);
  }
  visited[u]=1;
  f[u]=++tt;
}

int main(){
  int n; cin >> n;
  for(int i=1;i<=n;i++) visited[i]=0;
  for(int i=0;i<n;i++){
    int u,k; cin >> u >> k;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }
  dfs(1);
  for(int i=1;i<=n;i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
#define REP0(i,n) for(int i=0;i<n;i++)
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
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){
  REP0(i,n) 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();
      }
    } else{
      S.pop();
      color[u]=BLACK;
      F[u]=++tt;
    }
  }
}
void DFS(){
  REP0(i,n){
    color[i]=WHITE;
    nt[i]=0;
  }
  tt=0;
  REP0(u,n) if(color[u]==WHITE) DFS_visit(u);
  REP0(i,n) printf("%d %d %d\n",i+1,D[i],F[i]);
}
int main(){
  int u,k,v;
  scanf("%d",&n);
  REP0(i,n){
    REP0(j,n) M[i][j]=0;
  }
  REP0(i,n){
    scanf("%d %d",&u,&k);
    REP(j,k){
      scanf("%d",&v);
      M[--u][--v]=1;
    }
  }
  DFS();
  return 0;
}