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<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 M[N][N], color[N], d[N], f[N], nt[N];
int tt,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 u) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(u);
	color[u] = BLACK;
	d[u] = ++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(v);	
			}
		} else {
			S.pop();
			color[u]  = BLACK;
			f[u] = ++tt;
		}
	}
}


void dfs() {
	for(int i = 0; i < n; i++){
		color[i] = WHITE; 
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	for(int i =0; i < n; i++ ) {
    	cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k,v;
	cin >> n;
	for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
      	M[i][j] = 0;
      }	
	}
	cin >> u >> k ;
	u--;
	for(int i = 0; i < k; i++ ) {
	   cin >> v;
	   v--;
	   M[u][v] = 1;	
	}	
	
	dfs();
	
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>

int main(){
    int n;
    scanf("%d",&n);
    int a[n+1][n+1];
    int i,j;
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)a[i][j]=0;
    for(i=1;i<=n;i++){
        int q,k;
        scanf("%d %d",&q,&k);
        for(j=1;j<=k;j++) {
            int p;
            scanf("%d",&p);
            a[q][p]=1;
        }
    }
    int time=0;
    std::stack<int>S;
    int ans[n+1][3];
    
    
    
    S.push(1);
    time++;
    ans[1][1]=time;
    
    int color[n+1];
    color[1]=1;
    for(i=2;i<=n;i++)color[i]=0;//0??????????¨????
    int lastcheck=0;
    
    while(lastcheck==0){
        while(S.size()>=1){
            int flag=0;//flag=0??????pop
            for(i=1;i<=n;i++){
                if(i!=S.top()&& a[S.top()][i]==1 &&color[i]==0){
                    S.push(i);
                    color[i]=1;
                    time++;
                    ans[i][1]=time;
                    flag=1;
                    break;
                }
            }
            if(flag==0){
                time++;
                ans[S.top()][2]=time;
                S.pop();
            }
        }
        lastcheck=1;
        for(i=1;i<=n;i++)if(color[i]==0){
            lastcheck=0;
            break;
        }
        if(lastcheck==0){
            S.push(i);
            time++;
            ans[i][1]=time;
            color[i]=1;
        }
    }
    
    
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,ans[i][1],ans[i][2]);
    }
    return 0;
}

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

#define MAX_N 101

int n, t;
vector<vector<int> > A(MAX_N, vector<int>(MAX_N, 0));
stack<int> S;
int d[MAX_N] = {};
int f[MAX_N] = {};

void df(int e)
{
    d[e] = ++t;
    for (int i = 1; i <= n; i++) {
        if (A[e][i] && !d[i]) df(i);
    }
    f[e] = ++t;
}

int main()
{
    int i, u, k, v;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            A[u][v]++;
        }
    }
    t = 0;
    df(1);
    for (i = 1; i <= n; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

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, M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

//uに隣接するvを番号順に取得
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){
    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=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;//u頂点の終了時刻
        }
    }
}

void dfs(){
    //初期化
    for (int i=0; i<n; i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    
    //未訪問のuを始点として深さ優先探索
    for (int u=0; u<n; u++){
        if(color[u]==WHITE) dfs_visit(u);
    }
    for (int i=0; i<n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

C++: #include <iostream>
#include <stack>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int color[MAX],d[MAX],f[MAX];
int n,t;
int N[MAX][MAX];
void dfs(int u){
    color[u] = GRAY;
    d[u] = ++t;
    for(int v=0;v<n;v++){
        if(N[u][v]!=0&&color[v]==WHITE){
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}
void dfs_init(){
    t = 0;
    for(int i=0;i<n;i++){
        color[i] = WHITE;
    }
    for(int i=0;i<n;i++){
        if(color[i]==WHITE)
            dfs(i);
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" " <<f[i]<<endl;
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            N[i][j] = 0;
        }
    }
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int v;
            cin>>v;
            N[i][v-1] = 1;
        }
    }
    dfs_init();
    return 0;
}