Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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

const int Max = 105;
int G[Max][Max], color[Max], d[Max], f[Max];
int t, n;

void dfs_visit(int u)
{
    color[u] = 0;
    d[u] = ++t;
    for(int j=0; j<n; j++)
    {
        if(!G[u][j]) continue;
        if(color[j]==-1)
            dfs_visit(j);
    }
    color[u] = 1;
    f[u] = ++t;
}
void dfs()
{
    memset(color, -1, sizeof(color));
    t = 0;
    for(int i=0; i<n; i++)
    {
        if(color[i]==-1)
            dfs_visit(i);
    }
    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++)
    {
        cin >> u >> k;
        for(int j=0; j<k; j++)
        {
            cin >> v;
            G[u-1][v-1] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #include<bits/stdc++.h>
//cout<<setprecision(1)<<fixed<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;
#define eps 1e-7
//#define Kongxiangzhouye
int n;
int a[123][123];
int st[123];
int ed[123];
int now;
void dfs(int local){
	st[local]=now++;
	int flag=1;
	for(int i=1;i<=n;i++){
		if(a[local][i]==1){
			if(st[i]==0){
				flag=0;
				dfs(i);
			}
		}
	}
	ed[local]=now++;
}
int main(){
	ios::sync_with_stdio(false);
	#ifdef Kongxiangzhouye
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	while(cin>>n){
		memset(a,0,sizeof(a));
		memset(st,0,sizeof(st));
		memset(ed,0,sizeof(ed));
		for(int i=0;i<n;i++){
			int t,m;
			cin>>t>>m;
			for(int i=0;i<m;i++){
				int te;
				cin>>te;
				a[t][te]=1;
			}
			now=1;
		}
		dfs(1);
		for(int i=1;i<=n;i++){
			cout<<i<<" "<<st[i]<<" "<<ed[i]<<endl;
		}
	}
	return 0;
}

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

int n;
int cnt1 = 0; 
vector<int> d(n);
vector<int> f(n);
void dfs(const Graph &G, int v){
    cnt1++;
    d[v - 1] = cnt1;
    for(auto nv : G[v - 1]){
        if(d[nv - 1] != 0) continue;
        dfs(G, nv);
    }
    cnt1++;
    f[v - 1] = cnt1;
}

int main(){
    cin >> n;
    Graph G(n); 
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(b == 0) continue;
        for(int j = 0; j < b; j++){
            int x; cin >> x;
            G[a - 1].push_back(x);
        }
    }
    d.assign(n, 0);
    f.assign(n, 0);
    for(int i = 1; i <= n; i++){
      if(d[i - 1] == 0) dfs(G, i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i - 1] << " " << f[i - 1] << endl; 
    }
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

using Graph = vector<vector<ll>>;
Graph G;
ll d[110], f[110];

void DFS(ll v, ll &t)
{
	if (d[v] != -1) return;
	d[v] = t;

	++t;
	for (auto &nv : G[v])
	{
		DFS(nv, t);
	}
	f[v] = t;
	++t;
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	G.resize(N);
	for (ll i = 0; i < N; ++i)
	{
		ll n, k; cin >> n >> k;
		--n;
		for (ll j = 0; j < k; ++j)
		{
			ll v; cin >> v;
			--v;
			G[n].push_back(v);
		}
		sort(G[n].begin(), G[n].end());
	}
	fill(d, d+110, -1);
	fill(f, f+110, -1);

	ll t = 1;
	for (ll v = 0; v < N; ++v)
	{
		if (d[v] == -1)
			DFS(v, t);
	}

	for (ll i = 0; i < N; ++i)
	{
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
}

C++: //?????????????????¢?´¢
//??????????????????????????????????????¢?´¢
#include<iostream>
#include<cstdio>
#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;
        }
    }
}

void dfs(){
    int u;
    for(int i = 0; i < n; i++) nt[i] = 0;
    
    for( u = 0; u < n; u++){
        //????¨????u?????¢??????????????????dfs
        if(d[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, v, k, j,i;
    
    cin >> n;
    
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++) M[i][j] = 0;
   
    for(i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for(j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}