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++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(n));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
			t[w].push_back(i);
		}
		sort(t[i].begin(),t[i].end());
	}
	for(int i=0;i<n;i++){
		sort(t[i].begin(),t[i].end());
	}
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	while(S.size()){
		g++;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
		}
		if(a==-1){
			H[S.top()]=g;
			S.pop();
		}
		else{
			F[a]=1;
			G[a]=g;
			S.push(a);
		}
	}
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}

C++: #if 0

#endif

#include <iostream>
#include <vector>
using namespace std;

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[cur][dst]==1&&c[dst]==0){
			cout<<1<<endl;
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	int G[110][110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			G[u][tmp]=1;
		}
	}
	
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;

bool A[110][110],flag[110];
int in[110],out[110];
int n,now=1;
stack<int> S;

void dfs_visit(int u){
	flag[u]=true;
	for(int i=1;i<=n;i++){
		if(A[u][i]==true && flag[i]==false) {
			S.push(i);
			in[i]=now++;
			dfs_visit(i);
		}
	}
	int x=S.top();
	S.pop();
	out[x]=now++;
	return ;
}

void dfs(){
	S.push(1);in[1]=now++;
L1:	while(S.empty()==0){
		int x=S.top();
		dfs_visit(x);
	}
	for(int i=1;i<=n;i++){
		if(flag[i]==false){
			S.push(i);in[i]=now++;goto L1;
		}
	}
	for(int i=1;i<=n;i++) cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return ;
}

int main (){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		flag[i]=false;
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	dfs();
	return 0;

}

C++: #include <iostream>
#include <stack>
using namespace std;
#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;
int nt[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 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;
        }
    }
}

void dfs(){
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    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(void){
    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<bits/stdc++.h>
using namespace std;
const int MAXN =  100+7;
struct node {
    int id;
    node* next;
};
node* g[MAXN];
bool visit[MAXN];
int d[MAXN];
int f[MAXN];
int mytime;
stack<int> s;
void dfs(int i){
    node* p = g[i];
    while(p->next!=NULL){
        p=p->next;
        if(visit[p->id]==false){
            s.push(p->id);
            mytime++;
            d[p->id] = mytime;
            visit[p->id] = true;
            dfs(p->id);
        }

    }
    s.pop();
    mytime++;
    f[i] = mytime;

}
int main() {
//    freopen("../in.txt", "r", stdin);
    memset(visit, false, sizeof(visit));
    int n;
    scanf("%d", &n);
    int i;
    for(i = 1; i <= n; i++) {
        g[i] = (node*)malloc(sizeof(node));
        g[i]->next = NULL;
    }
    for(i = 0; i < n; i++) {
        int num;
        int k;
        scanf("%d", &num);
        scanf("%d", &k);
        int j;
        for(j = 0; j < k; j++) {
            int r;
            scanf("%d", &r);
            node* t = (node*)malloc(sizeof(node));
            t->id = r;
            t->next = NULL;
            node* p = g[num];
            while(p->next != NULL) p = p->next;
            p->next = t;
        }
    }
    mytime = 0;
    while(true){
        int u;
        int g = -1;
        for(u = 1; u <= n; u++){
            if(visit[u]==false){
                g = u;
                break;
            }
        }
        if(g==-1){
            break;
        }
        s.push(g);
        mytime++;
        d[g] = mytime;
        visit[g] = true;
        dfs(g);
    }

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