Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1 
#define BLACK 2
 
int n, M[N][N];
int color[N], d[N], f[N], tt; 

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v = 0; v < n; v++) {
		if(M[u][v] == 0) continue;
		if(color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs() {
	int u;
	for(u = 0; u < n; u++) color[u] = WHITE;
	tt = 0;
	
	for(u = 0; u < n; u++) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	
	for(u = 0; u < n; u++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}
 
int main() {
    int u, k, v, i, j;
    
    scanf("%d", &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++) {
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++ ) {
           scanf("%d", &v);
           v--;
           M[u][v] = 1; 
        }       
    }
     
     
    dfs();
     
    return 0;
}

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

int n, dd[100], f[100], tmap[100][100];
int color[100], t = 1;
stack<int> S;

int a(){
	int d = S.top();
	dd[d] = t;
	t++;
	color[d] = 1;
	cout << d << "??????" <<endl;
	for (int i = 1; i <= n; i++){
		if (color[i] == 0 && tmap[d][i] == 1){
			cout << d << "  " << i << "  " << t << endl;
			S.push(i);
			a();
		}
	}
	cout << d << "??????" << endl;
	f[d] = t;
	t++;
	return 0;
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		dd[i] = f[i] = color[i] = 0;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	S.push(1);
	a();
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = 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 x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

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

stack<int> S;
int n, x[10000][10000], a, b, c, d, _time=2;
int y[10000][3];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			x[i][d] = 1;
			x[d][i] = 1;
		}
	}
	S.push(1);
	y[1][1] = 1;
	while (!S.empty()) {
		a = S.top();
		for (int i = 1; i <= n; i++) {
			if (x[a][i] == 1 && y[i][0] == 0) {
				y[i][0] = 1;
				y[i][1] = _time;
				S.push(i);
				goto Exit;
			}
		}
		S.pop();
		y[a][2] = _time;
	Exit:;
		_time++;
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << y[i][1] << ' ' << y[i][2] << endl;
	}
	return 0;
}

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

static const int M_NUM = 100;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int adj_M[M_NUM][M_NUM];
int v_num, Time(0);
int visit_state[M_NUM], D_time[M_NUM], C_time[M_NUM];

void DepthFirstSearch_Recursion(int vertex) 
{
    visit_state[vertex] = GRAY;
    D_time[vertex] = ++Time;
    for (int i = 0; i < v_num; ++i)
    {
        if (adj_M[vertex][i] && visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);
    }
    visit_state[vertex] = BLACK;
    C_time[vertex] = ++Time;
}

int main() 
{
    int v_id, v_degree, adj_v;
    cin >> v_num;

    for (int i = 0; i < v_num; ++i) 
    {
        for (int j = 0; j < v_num; ++j) 
        {
            adj_M[i][j] = 0;
        }
    }

    for (int i = 0; i < v_num; ++i) 
    {
        cin >> v_id >> v_degree;
        v_id--;
        for (int j = 0; j < v_degree; ++j) 
        {
            cin >> adj_v;
            adj_v--;
            adj_M[v_id][adj_v] = 1;
        }
    }

    for (int i = 0; i < v_num; ++i) visit_state[i] = WHITE;

    for (int i = 0; i < v_num; ++i) if (visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);

    for (int i = 0; i < v_num; ++i) 
    {
        cout << i + 1 << " " << D_time[i] << " " << C_time[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v;
vector<int> d,f,visited;
int cnt = 0;

void dfs(int node, vector<vector<int> > &graph)
{
  //cout << node+1 << " " << cnt+1 << "\n";
  d[node] = cnt;
  cnt++;
  visited[node] = 1;
  for(int i = 0; i<v[node].size(); i++)
  {
    if(visited[v[node][i]] == 1) continue;
    dfs(v[node][i], v);
  }
  //visited[node] = 0;
  //cout << node+1 << " " << cnt+1 << "\n";
  f[node] = cnt;
  cnt++;
}

int main()
{
  int n; cin>>n;
  d.resize(n, 0);
  f.resize(n, 0);
  visited.resize(n, 0);
  v.resize(n);
  for(int i=0; i<n; i++)
  {
    int id, u; cin>>id>>u;
    id--;
    v[i].resize(u);
    for(int j=0; j<u; j++)
    {
      int l; cin>>l;
      l--;
      v[id][j] = l;
    }
  }
  for(int i = 0; i < n; i++)
  {
    if (visited[i]) continue;
    else dfs(i, v);
  }
  for(int i = 0; i<n; i++)
  {
    cout << i+1 << " " << d[i] + 1 << " " << f[i] + 1 << "\n";
  }
  return 0;
}