Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while(!S.empty()) {
		int u = S.top();
		int v;
		for(v = 0; v < n; v++) {
			if(M[u][v] == 0) continue;
			if(color[v] != WHITE) continue;
			break; 
		}
		if(v != n) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
		    }
		} 
		for(v = 0; v < n; v++) {
			if(M[u][v] == 1) break;
		}
		if(v == n){
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;
		
	for(int u = 0; u < n; u++) {
		if(color[u]) dfs_visit(u);
	}

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

int main() {
	int k , u, v;
	cin >> 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++) {
		cin >> u >> k;
	    u--;
	    for(int i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

C++: #include <iostream>
#include <utility>
#define N 	100

using namespace std;

int T[N+1][N+1];
pair<int , int> M[N+1];
int t = 0;

void init(){
	for (int i = 0; i < 100; ++i)
	{
		M[i].first = 0;
		M[i].second = 0;
		for (int j = 0; j < 100; ++j)
		{
			T[i][j] = 0;
		}
	}
}

void DispTable(int n){
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			cout << T[i][j];
			if(j!=n) cout << " ";
		}
		cout << endl;
	}
}

void DispM(int n){
	for (int i = 1; i<=n; i++)
	{
		cout << i << " " << M[i].first << " " << M[i].second << endl;
	}
}

void dfs(int cur,int n){
	t++;
	M[cur].first = t;
	// cerr << "visiting " << cur << " " << t << endl;

	for (int i = 1; i <= n; ++i)
	{
		if(i != cur && T[cur][i] == 1 && M[i].first == 0) dfs(i,n);
	}
	t++;
	M[cur].second = t;
}

int main(){
	int n;
	cin >> n;
	init();
	for (int i = 0; i < n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			int v;
			cin >> v;
			T[u][v] = 1;	
		}
	}
	// DispTable(n);
	dfs(1,n);
	DispM(n);
	return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int times=1;

void dfs(int now,vector<int> &fvisit,vector<int> &fin, vector<vector<int>> &vs)
{
  if(fvisit[now]==-1)
  {
    fvisit[now]=times;
    times++;
  }
  else return;
  int i;
  rep(i,vs[now].size())
  {
    if(fvisit[vs[now][i]]==-1)
    {
      dfs(vs[now][i],fvisit,fin,vs);
    }
  }
  fin[now]=times;
  times++;
}

int main()
{
  int n;cin>>n;
  vector<vector<int>> vs(n);
  int i,j;
  rep(i,n)
  {
    int u,k;cin>>u>>k;
    u--;
    rep(j,k)
    {
      int vj;cin>>vj;
      vj--;
      vs[u].emplace_back(vj);
    }
  }
  vector<int> fvisit(n,-1);
  vector<int> fin(n,-1);
  rep(i,n)
  {
    dfs(i,fvisit,fin,vs);
  }
  rep(i,n)
  {
    cout<<i+1<<' '<<fvisit[i]<<' '<<fin[i]<<endl;
  }
}

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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vector<vector<int>> g;
vector<int> d, f;

int dfs(int v, int t)
{
    // cout << v << " ";
    if (f[v] != INT32_MAX)
    {
        return f[v];
    }
    if (d[v] != INT32_MAX && f[v] == INT32_MAX)
    {
        return t - 1;
    }

    d[v] = min(d[v], t);

    int tt = t + 1;
    for (auto to : g[v])
    {
        if (v == to)
            continue;
        tt = max(tt, dfs(to, tt) + 1);
    }
    f[v] = min(tt, f[v]);

    return tt;
}

int main()
{
    int n;
    cin >> n;
    g = vector<vector<int>>(n, vector<int>());
    d = vector<int>(n, INT32_MAX);
    f = vector<int>(n, INT32_MAX);

    rep(i, n)
    {
        int k;
        cin >> k >> k;
        rep(j, k)
        {
            int t;
            cin >> t;
            t--;
            g[i].emplace_back(t);
        }
    }

    int t = 1;
    rep(i, n)
    {
        if (f[i] == INT32_MAX)
        {
            t = dfs(i, t) + 1;
        }
    }

    rep(i, n)
    {
        cout << (i + 1) << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include<stdio.h>

int d[100],f[100],n,g[100][100],time=1;

int func(int m){
    d[m]=time++;
    int i,j;
    for(i=0;i<n;i++){
        if(g[m][i]==1 && d[i]==0){
            func(i);
        }
    }
    f[m]=time++;
}

int main(void){
    int i, j, u, k, v;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            g[u-1][v-1]=1;
        }
    }
    func(0);
    for(i=0;i<n;i++){
        if(d[i]==0){
            func(i);
        }
    }
    for(i=0;i<n;i++){
        printf("%d %d %d\n",i+1,d[i],f[i]);
    }
    return 0;
}