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 <iostream>
using namespace std;
struct Node{
  int u;
  int k;
  int v[99];

  int start;
  int finish;
};

int deep(Node nod[],int x,int count){
  if(nod[x].start)
    return count;

  nod[x].start=(++count);
  cout << nod[x].u << " " << count << endl;
  for(int i=0; i<nod[x].k; i++)
    count = deep(nod,nod[x].v[i]-1,count);

  nod[x].finish= (++count);
  return count;
}

int main(){
  int n,count=0;
  Node nod[100];

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> nod[i].u >> nod[i].k;

    for(int j=0; j<nod[i].k; j++)
      cin >> nod[i].v[j];

    nod[i].start=0;
    nod[i].finish=0;
    }

    count = deep(nod,0,count);

    for(int i=0; i<n; i++){
      cout << nod[i].u << " " << nod[i].start << " " << nod[i].finish << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;

vector<vector<int>> G(101);
int d[101] = {}, f[101] = {};

void dfs(int from, int& time) {
    if (d[from] == -1) {
        time++;
        d[from] = time;

        for (auto v: G[from]) dfs(v, time);

        time++;
        f[from] = time;
    }
}

int main() {
    int N;
    cin >> N;
    
    rep(i, N) {
        int u, k, vj;
        cin >> u >> k;
        rep(j, k) {
            cin >> vj;
            G[u].push_back(vj);
        }
    }

    int time=0;
    rep(i, N+1) d[i] = -1;
    for (int i=1; i<=N; i++) {
        if (d[i] == -1) dfs(i, time);
    }
    
    for (int i=1; i<=N; i++) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

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

static const int DFS_VISIT_NO   = 0;
static const int DFS_VISIT_NOW  = 1;
static const int DFS_VISIT_DONE = 2;

static int g_time = 0;
static int g_setime[100][2] = {0};

void DfsVisit(vector<int> &graph, int node, vector<int> &state)
{
    int i;
    int nnum;
    int target;

    ++g_time;
    g_setime[node][0] = g_time;

    state[node] = DFS_VISIT_NOW;
    
    nnum = graph[node].size();

    for (i = 0; i < nnum; i++) {
        target = graph[node][i];
        if (state[target] != DFS_VISIT_DONE) {
            DfsVisit(graph, target, state);
        }
    }

    state[node] = DFS_VISIT_DONE;

    ++g_time;
    g_setime[node][1] = g_time;

    return;
}


void DFS(vector<int> &graph, int num)
{
    int i;
    vector<int> state;

    for (i = 0; i < num; i++) {
        state[i] = DFS_VISIT_NO;
    }

    for (i = 0; i < num; i++) {
        if (state[i] == DFS_VISIT_NO) {
            DfsVisit(graph, num, i, state);
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int target, tnum, node;
    int num;

    scanf("%d", &num);
    vector<int> graph[num];

    for (i = 0; i < num; i++) {
        scanf("%d" "%d", &target, &tnum);
        --target;
        for (j = 0; j < tnum; j++) {
            scanf("%d", &node);
            --node;
            graph[target].push_back(node);
        }
    }

    DFS(graph, num);
}

C++: #include <iostream>
#include <algorithm>
#include <stack>


using namespace std;


stack<int> visiting;

#define MAX 100
bool adj[MAX + 2][MAX + 2];
int d[MAX + 1], f[MAX + 1];
bool discovered[MAX + 1];
int tt, n;


void dfs(int v)
{
    visiting.push(v);
    discovered[v] = true;
    d[v] = ++tt;

    while (!visiting.empty()) {
        int now = visiting.top();
        int i;
        for (i = 1; i <= n; i++) {
            if (adj[now][i] && !discovered[i])
                break;
        }

        if (!discovered[i] && i <= n) {
            d[i] = ++tt;
            visiting.push(i);
            discovered[i] = true;
        } else {
            f[now] = ++tt;
            visiting.pop();
        }
    }
}


int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            adj[id][v] = true;
        }

        discovered[i] = false;
    }

    for (int i = 1; i <= n; i++)
        if (!discovered[i])
            dfs(i);


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

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
bool ok[10005];
int d[10005];
int f[10005];
vector<int> e[10005];
int step=0;
void dfs(int i){
	ok[i]=1;
	step++;
	d[i]=step;
	for(int j=0;j<e[i].size();j++)
		if(!ok[e[i][j]])
			dfs(e[i][j]);
	step++;
	f[i]=step;
}
void solve(){
	for(int i=1;i<=n;i++)if(!ok[i])dfs(i);
	for(int i=1;i<=n;i++)
		cout<<i<<' '<<d[i]<<' '<<f[i]<<"\n";
}
int main(){
//	freopen("a.txt","r",stdin);
	cin>>n;
	int u,k,v;
	for(int i=1;i<=n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++)cin>>v,e[u].push_back(v);
	}
	solve();
	return 0;
}