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) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

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

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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)
	}

	dfs(vertexId(1), 0, 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 <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        if(itr_v != G[u].end()){
            itrNum[u]++;
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(i);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

void dfs(int n, vector<vector<int> > &G, int s, int *d, int *f, int &t) {
    d[s] = t++;
    for (int i = 0; i < G[s].size(); i++) {
        int v = G[s][i];
        
        if (d[v] != -1)
            continue;

        dfs(n, G, v, d, f, t);
    }
    f[s] = t++;
}

int main() {
    int n, u, k, v;
    cin >> n;
    vector<vector<int> > G(n);
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[i].push_back(v-1);
        }
    }

    int *f = new int[n], *d = new int[n];
    for (int i = 0; i < n; i++)
        f[i] = d[i] = -1;

    int t = 1;
    for (int i = 0; i < n; i++) {
        if (d[i] == -1)
            dfs(n, G, i, d, f, t);
    }

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if(matrix[cur-1][l[cur][i]-1]==1)
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
}
int main()
{
    int n;
    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;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    dfs(1);
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<stack>

const static int MAX = 100;
int G[MAX][MAX];
int nt[MAX];
int n;

int nextNode(int x){
    for(int i = nt[x]; i < n; i++){
	if(G[x][i] == 1){
	    nt[x] = i + 1;
	    return i;
	}
    }
    return -1;
}

int main(void){
    std::stack<int> st;
    int color[MAX], a[MAX], b[MAX];
    int u, k, v, time;

    time = 0;
    std::cin >> n;

    for(int i = 0; i < n; i++){
	color[i] = 0;
    }

    for(int i = 0; i < n; i++){
	std::cin >> u >> k;
	u--;
	for(int j = 0; j < k; j++){
	    std::cin >> v;
	    v--;
	    G[u][v] = 1;
	}
    }

    for(int i = 0; i < n; i++){
	if(color[i] == 0){
	    st.push(i);
	    color[i] = 1;
	    a[i] = ++time;
	}
	while(!st.empty()){
	    int cur = st.top();
	    int next = nextNode(cur);
	    if(color[next] == 0 && next != -1){
	        st.push(next);
	        color[next] = 1;
	        a[next] = ++time;
	    }
	    if(next == -1){
		st.pop();
		b[cur] = ++time;
	    }
	}
    }

    for(int i = 0; i < n; i++){
        std::cout << i+1 << " " << a[i] << " " << b[i] << std::endl;
    }


    return 0;

}

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

int DFS(bool path[110][110],int begin[],int end[],int v,int n,int t){
    t++;
    begin[v]=t;
    for(int i=0;i<n;i++){
        if(path[v][i]&&begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    t++;
    end[v]=t;
    return t;
}

int main(void){
    int n,u,k,i,j,x,t;
    bool path[110][110];
    int begin[110],end[110];
    memset(path,0,sizeof(path));
    memset(begin,0,sizeof(begin));
    cin>>n;
    for(i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(j=0;j<k;j++){
            cin>>x;
            x--;
            path[u][x]=true;
        }
    }
    
    t=0;
    for(i=0;i<n;i++){
        if(begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    
    for(i=0;i<n;i++){
        cout<<i+1<<" "<<begin[i]<<" "<<end[i]<<endl;
    }
    
    return 0;
}