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 <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxx = 110;
int n, m[maxx][maxx];
int u, num, v;
int d[maxx], f[maxx];
int flag[maxx];
int nowtime = 1;

void dfs(int u) {

	// ??\?????¶??´
	flag[u] = 1;
	d[u] = nowtime++;
	for (int i = 1; i <= n; i++) {
		if (flag[i] == 0 && m[u][i] == 1) {
			dfs(i);
		}
	}
	//????????¶??´
	f[u] = nowtime++;
}

int main()
{

	scanf("%d", &n);
	memset(m, 0, sizeof(m));
	memset(f, 0, sizeof(f));
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &u, &num);
		for (int j = 1; j <= num; j++) {
			scanf("%d", &v);
			m[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if(flag[i] == 0)
			dfs(i);
	}
	for (int i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;


int n, t = 0;
vector<int> g[105];
bool seen[105];
int d[105], f[105];

void dfs(int v){
    seen[v] = true;
    d[v] = t;
    for(int nv : g[v]){
        if(seen[nv]) continue;
        t++;
        dfs(nv);
    }
    t++;
    f[v] = t;
}

int main(){
    cin >> n;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        rep(j, b){
            int c;
            cin >> c;
            g[a].push_back(c);
        }
    }
    rep(k, n) g[0].push_back(k + 1);

    memset(seen, 0, sizeof(seen));
    dfs(0);

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

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

static const int N = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;
int d[N], f[N],tt;
int color[N],n,M[N][N];


void dfs_visit(int u) {
	int v;
	d[u] = ++tt;
	color[u] = Gray;
	rep(v,n){
		if (M[u][v] == 0) continue;
		if (color[v] == White) dfs_visit(v);
	}
	color[u] = Black;
	f[u] = ++tt;
}

void dfs() {
	int u;
	rep(u, n)color[u] = White;
	rep(u, n) {
		if (color[u] == White) dfs_visit(u);
	}
	rep(u, n) {
		cout << u + 1 << ' ' << d[u] << ' ' << f[u] << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	int i;
	rep(i, n) {
		int u, k, v;
		cin >> u >> k;
		u--;
		int j;
		rep(j, k) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <stdio.h>
int n,M[100][100],C[100],d[100],f[100],t;
void visit(int );
void dfs();
int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}
void dfs(){
  int i;
  for(i=0;i<n;i++)C[i]=0;
  t=0;
  for(i=0;i<n;i++)if(C[i]==0)visit(i);
  for(i=0;i<n;i++)printf("%d %d %d\n",i+1,d[i],f[i]);
}
void visit(int k){
  int i;
  C[k]=1;
  d[k]=++t;
  for(i=0;i<n;i++){
    if(M[k][i]==0)continue;
    if(C[i]==0)visit(i);
  }
  C[k]=2;
  f[k]=++t;
}

C++: #include <stdio.h>
#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;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0;v = n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] == BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    
    for(u = 0;u < n;u++) color[u] = WHITE;
    tt = 0;
    
    for(u = 0;u < n;u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n;u++){
        printf("%d %d %d\n",u + 1,d[u],f[u]);
    }
}

int main(void){
    int u,v,k,i,j;
    
    scanf("%d", &n);
    for(i = 0;i < n;i++){
        for(j = 0;j < n;j++) M[i][j] = 0;
    }
    
    for(i = 0;i < n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j = 0;j < k;j++){
            scanf("%d",&v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
}