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 <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int M[N][N]={0};
int n;
int color[N]={WHITE},one[N],two[N];
int tt=0,aaa[N]={1};

int next(int num){
    for(int i=aaa[num];i<=n;i++){
        aaa[num]=i+1;
        if(M[num][i]) return i;
    }
    return -1;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    one[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                one[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            two[u]=++tt;
        }
    }
}

void dfs(){
    for(int i=1;i<=n;i++){
        if(color[i]==WHITE) dfs_visit(i);
    }
    for(int i=1;i<=n;i++){
        cout << i << " " << one[i] << " " << two[i] << endl;
    }
}




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

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int t = 0;
int n;

void dfs_v(v2& a, v2& b, int p){
	p--;
	if(a.at(p).at(0) == -1){
		return;
	}
	b.at(p).push_back(++t);
	a.at(p).at(0) = -1;
	rep(i, a.at(p).at(1)){
		int np = a.at(p).at(2+i);
		dfs_v(a, b, np);
	}
	b.at(p).push_back(++t);
}
void dfs(v2& a, v2& b){
	rep(i, n){
		if(a[i][0] != -1){
			dfs_v(a, b, a[i][0]);
		}
	}
}

int main(){
	cin >> n;
	v2 a(n, v1(0));
	v2 b(n, v1(0));
	rep(i, n){
		int m;
		cin >>m;
		a[i].push_back(m);
		b[i].push_back(m);
		int x;
		cin >> x;
		a.at(i).push_back(x);
		rep(j, x){
			int y;
			cin >> y;
			a.at(i).push_back(y);
		}
	}
	dfs(a, b);
	rep(i, n){
		rep(j, 3){
			cout << b[i][j];
			if(j != 2) cout << " ";
			else cout << endl;
		}
	}
}

C++: #include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = (int)1e2 + 10;

int n;
vector<int> g[MAXN];
int vis[MAXN];
int st[MAXN],en[MAXN];
int clk;

void DFS(int u){
    vis[u]=1;
    st[u]=++clk;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(vis[v]) continue;
        DFS(v);
    }
    en[u]=++clk;
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int u,k; scanf("%d%d",&u,&k);
        while(k--){
            int v; scanf("%d",&v);
            g[u].push_back(v);
        }
        sort(g[u].begin(),g[u].end());
    }
    for(int i=1;i<=n;i++)if(!vis[i]) DFS(i);
    for(int i=1;i<=n;i++) printf("%d %d %d\n",i,st[i],en[i]);
}

int main(){
    work();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,lis[111][111]={},d[111]={},f[111],t=1;

void dfs(int now=1){
  d[now]=t++;
  for(int i=1;i<=n;i++)
    if(lis[now][i]&&d[i]==0)dfs(i);
  f[now]=t++;
}

int main(){
  cin>>n;
  for(int c=0;c<n;c++){
    int u,k,v;
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v;
      lis[u][v]=1;
    }
  }
  dfs();
  for(int i=1;i<=n;i++)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;  
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

struct Timestamp{
	int discovered;
	int finished;
};

int main(){
	int n;
	cin >> n;

	vector<int> A[n+1];
	bool reached[n+1]{};
	int v1, v2, deg;
	r(i, n){
		cin >> v1 >> deg;

		r(j, deg){
			cin >> v2;
			A[v1].push_back(v2);
		}
	}

	Timestamp ts[n+1];
	for(int i = 1; i <= n; i++){
		ts[i].discovered = 0;
		ts[i].finished = 0;
	}
	ts[1].discovered = 1;

	stack<int> s;
	s.push(1);
	int time = 1;
	while(!s.empty()){
		v1 = s.top();

		bool hasNext = false;
		for(int v2 : A[v1]){
			if(!reached[v2]){
				reached[v2] = true;
				s.push(v2);
				hasNext = true;
				break;
			}
		}

		if(!ts[v1].discovered){
			time++;
			ts[v1].discovered = time;
		}

		if(!hasNext){
			time++;
			ts[v1].finished = time;
			s.pop();
		}
	}

	for(int i = 1; i <= n; i++){
		printf("%d %d %d\n", i, ts[i].discovered, ts[i].finished);
	}

	return 0;
}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int adj_matrix[N_MAX+1][N_MAX+1];

int d[N_MAX+1];
int f[N_MAX+1];

int t;
int n;

void dfs_visit(int id) {
    d[id] = ++t;
    FOR(i,1,n+1) {
        if (adj_matrix[id][i] && !d[i]) {
            dfs_visit(i);
        }
    }
    f[id] = ++t;
}

void dfs() {
    FOR(i,1,n+1) {
        if (!d[i]) {
            dfs_visit(i);
        }
    }
}

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

    cin >> n;

    int id, k, v;
    FOR(i,0,n) {
        cin >> id;
        cin >> k;
        FOR(j,0,k) {
            cin >> v;
            adj_matrix[id][v] = 1;
        }
    }

    dfs();

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

    return 0;
}