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>
#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;
}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}

	system("pause");

}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define N 2000

using namespace std;
vector<vector<int> > pa;
vector<vector<int> > ch;
int first[N] = {0};
int second[N] = {0};
int timestamp = 0;
void dfs(int x) {
    if (ch[x].empty()) {
        return;
    } else {
        for (int i = 0; i < ch[x].size(); i++) {
            if (first[ch[x][i]] * second[ch[x][i]] == 0) {
                timestamp++;
                first[ch[x][i]] = timestamp;
                dfs(ch[x][i]);
                timestamp++;
                second[ch[x][i]] = timestamp;
            }
        }
        return;
    }
}
int main() {
    int n;
    cin >> n;
    int temp = n;
    pa.clear(); pa.resize(N + 5);
    ch.clear(); ch.resize(N + 5);
    while (temp--) {
        int u, k, v;
        cin >> u >> k;
        for (int i = 0; i < k; i++) {
            cin >> v;
            pa[v].push_back(u);
            ch[u].push_back(v);
        }
    }
    int an = 0;
    for (int i = 1; i <= n; i++) {
        if (pa[i].empty()) {
            an = i;
            continue;
        }
        if (ch[i].empty()) {
            continue;
        }
        sort(pa[i].begin(), pa[i].end(), less<int>());
        sort(ch[i].begin(), ch[i].end());
    }
    timestamp++;
    first[an] = timestamp;
    dfs(an);
    timestamp++;
    second[an] = timestamp;
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << first[i] << ' ' << second[i] << '\n';
    }
}

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

#define MAX 100

stack<int> G;
int Graph[MAX+1][MAX+1];
int result[MAX+1][2];
int n;
int cnt = 0;

void dfs(int idx) {
    bool bl = false;
    for(int i=1; i<=n; i++) {
        //もし一つでも残っているノードがあればpushする
        if(Graph[idx][i]==1) {
            Graph[idx][i] = 0;
            //cout << "push: " << i << endl;
            cnt++;
            result[i][0] = cnt;
            G.push(i);
            dfs(i);
            bl = true;
        }
    }
    //一つも残っていなかったらpopする
    if(bl==false) {
        //cout << "pop: " << G.top() << endl;
        cnt++;
        result[G.top()][1] = cnt;
        G.pop();
        if(G.empty()) {
            return;
        }
        else {
            dfs(G.top());
        }
    }
}

int main() {
    int idx, g_num, a;

    cin >>n;
    for(int i=0; i<n; i++) {
        cin >> idx >> g_num;
        for(int j=0; j<n; j++) {
            Graph[idx][j] = 0;
        }
        for(int j=0; j<g_num; j++) {
            cin >> a;
            Graph[idx][a] = 1;
        }
    }
    G.push(1);
    cnt++;
    result[1][0] = cnt;
    cout << "push: " << 1 << endl;
    dfs(1);

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

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int G[101][101];
bool Memo[101];
int d[101];
int f[101];
int count1;

void dfs(int i, int n) {
  if (Memo[i]) {
    count1++;
    d[i] = count1;
    Memo[i] = false;
    for (int j = 0; j < n; j++) {
      if (G[i][j] == 1) {
        dfs(j,n);
      }
    }
    count1++;
    f[i] = count1;
  }
}

int main() {
  int n;
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      G[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int row,col;
    scanf("%d %d",&row,&col);
    for (int j = 0; j < col; j++) {
      int d;
      scanf("%d",&d);
      G[row - 1][d - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) Memo[i] = true;
  count1 = 0;
  for (int i = 0; i < n; i++) {
    if (Memo[i]) dfs(i,n);
  }
  for (int i = 0; i < n; i++) printf("%d %d %d\n",i+1,d[i],f[i]);
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N,u,k,x,r=0;
vector<int>V[105];
bool f[105]={0};
P c[105];

void dfs(int p)
{
	if(f[p])return;
	r++;
	f[p]=1;
	c[p].first=r;
	for(int i=0;i<V[p].size();i++)
	{
		dfs(V[p][i]);
	}
	r++;
	c[p].second=r;
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d%d",&u,&k);u--;
		for(int j=0;j<k;j++)
		{
			scanf("%d",&x);x--;
			V[u].push_back(x);
		}
		sort(V[u].begin(),V[u].end());
	}
	dfs(0);
	for(int i=0;i<N;i++)
		printf("%d %d %d\n",i+1,c[i].first,c[i].second);
	return 0;
}