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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

vector<int> E[200];
int d[200]={}, f[200]={};

int func(int pos, int time){
    if(d[pos]>0){
        return time;
    }
    d[pos] = time;
    time++;
    for (int to : E[pos]){
        time = func(to, time);
    }
    f[pos] = time;
    time++;
    return time;
}

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            E[u].push_back(v);
        }
    }
    int time = 1;
    for (int i = 1; i <= n; i++){
        if(d[i]==0){
            time = func(i, time);
        }
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    // printf("%d\n", N);
    return 0;
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  t = 1;

  cin >> n;
  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;
    }
  }

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
int n;
int v,k,tm;
vector<int> graph[105];
int star[105],tend[105];//记录结束和开始
int vis[105];//纪律顶点是否被访问
void dfs(int u,int& deep)
{
    vis[u]=1;//表示该点已经被访问
    star[u]=deep++;
    sort(graph[u].begin(),graph[u].end());//排序
    for(int i:graph[u])
    {
        if(vis[i]==0){dfs(i,deep);}
    }
    tend[u]=deep++;
    return ;
}
int main()
{
    clr(star,0);clr(tend,0);
    clr(vis,0);
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>v>>k;
        while(k--)
        {
            cin>>tm;
            graph[v].push_back(tm);//连接的点
        }
    }
    int deep=1;
    dfs(1,deep);
    for(int i=1;i<=n;++i)
    {
        cout<<i<<" "<<star[i]<<" "<<tend[i]<<endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
static const int MAX = 100;

int adj[MAX][MAX] = {0};
int n;

enum Color {
  WHITE,
  GRAY,
  BLACK,
};

struct node {
  Color color;
  int begin;
  int end;
};

node nodes[MAX];

void paint(int id, Color c) {
  static int time = 1;
  nodes[id].color = c;
  if (c == GRAY)
    nodes[id].begin = time;
  else if (c == BLACK)
    nodes[id].end = time;
  time++;
}

int next(int id) {
  for (int i = 0; i < n; i++) {
    if (adj[id][i] == 1 && nodes[i].color == WHITE) {
      return i;
    }
  }
  return -1;
}

void visit(int id) {
  stack<int> S;
  S.push(id);
  paint(id, GRAY);

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v > -1) {
      paint(v, GRAY);
      S.push(v);
    } else {
      S.pop();
      paint(u, BLACK);
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i++) {
    nodes[i].color = WHITE;
  }
  for (int i = 0; i < n; i++) {
    if (nodes[i].color == WHITE)
      visit(i);
  }
}

void printNode(int i) {
  printf("%d %d %d\n", i+1, nodes[i].begin, nodes[i].end);
}

int main() {
  cin >> n;
  int id, nn, x;
  for (int i = 0; i < n; i++) {
    cin >> id >> nn;
    id--; // 0-based
    for (int j = 0; j < nn; j++) {
      cin >> x;
      x--; // 0-based
      adj[id][x] = 1;
    }
  }

  dfs();

  for (int i = 0; i < n; i++) {
    printNode(i);
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
// using ll = long long;
// using P = pair<int, int>;

const int N_MAX = 100;

int T = 1;
int d[N_MAX];
int f[N_MAX];
vector<int> v[N_MAX];

struct node{
    vector<int> near;
    int dis;
    int fin;
    bool found = false;
};

void dfs(int idx){
    d[idx] = T;
    ++T;
    rep(i, (int)v[idx].size()){
        int x = v[idx][i];
        if(d[x] == 0) dfs(x);
    }
    f[idx] = T;
    ++T;
}

int main() {
    int n;
    cin >> n;
    
    rep(i, n){
        int m, l;
        cin >> m >> l;
        --m;
        rep(j, l){
            int x;
            cin >> x;
            --x;
            v[m].push_back(x);
        }
    }
    
    rep(i, n){
        if(d[i] == 0) dfs(i);
    }
    
    rep(i, n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return 0;
}