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>
using namespace std;

int main(){
 int n,k,v,u;
  cin>>n;

  int V[100][100]; //隣接リスト
  int cnt[100];　//各点においてどこまでみたかの把握
  int d[100];
  int f[100];
  int time=1;
  int l=0;
  int come[100]; //その点はどこからきたかの把握

  //初期化
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      V[i][j]=0;
      cnt[j]=0;
      d[j]=0;
      f[j]=0;
      come[j]=0;
    }
  }
  //グラフ情報の読み込み
 int  m=0;
  for(int i=0;i<n;i++){
    cin>>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      V[u-1][m]=v;
      m++;
    }
    m=0;
  }


  //スタートは0
 d[0]=1;
 time++;
  while(1){

    if(time==2*n+1) break;
    //先がありかつそこは探索終了していない
    if(V[l][cnt[l]]!=0 && f[V[l][cnt[l]]-1]==0){ 
     
      if(d[V[l][cnt[l]]-1]==0) d[V[l][cnt[l]]-1]=time;

   come[V[l][cnt[l]]-1]=l;
      cnt[l]++;
      l=V[l][cnt[l]-1]-1; 

      time++;
      //先がないまたはさきが探索終了している
    }else{

      if(d[l]==0) d[l]=time;
       f[l]=time;
      l=come[l];
      time++;

    }

  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    cout<<V[i][j]<<" ";
    if(j==n-1) cout<<endl;
  }
  }
  */
  //出力
  for(int i=0;i<n;i++){

    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }


  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=1;
static const int GRAY=2;
static const int BLACK=3;

int n,M[N][N];
int color[N],d[N],f[N],nt[N],tt;

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++) ;
    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()
{
    for(int i=0;i<n;i++)
    {
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;

    for(int u=0;u<n;u++)
    {
        if(color[u]==WHITE) dfs_visit(u);
    }

    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++)
      for(int j=0;j<n;j++)
    {
        M[i][j]=0;
    }

    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;
        }
    }
    dfs();
    return 0;
}

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

void dfs(vector<vector<int> > &G, vector<bool> &seen, vector<int> &d, vector<int> &f, int v, int &t) {
    seen[v] = true;
    d[v] = ++t;
    for (int i = 0; i < G[v].size(); i++) {
        if (seen[G[v][i]]) continue;
        dfs(G, seen, d, f, G[v][i], t);
    }
    f[v] = ++t;
}

void print(int n, vector<int> &d, vector<int> &f) {
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

    vector<bool> seen(n, false);
    vector<int> d(n), f(n);
    int t = 0;
    for (int i = 0; i < n; i++) {
        if (seen[i]) continue;
        dfs(G, seen, d, f, i, t);
    }
    print(n, d, f);

    return 0;
}

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

const int MAX_N = 110;
int G[MAX_N][MAX_N];
int D[MAX_N], F[MAX_N], V[MAX_N];

void dfs(int u, int n, int& count) {
  int i;
  V[u] = 1;
  D[u] = ++count;
  for (i = 0; i < n; ++i) {
    if (G[u][i] && !V[i]) {
      dfs(i, n, count);
    }
  }
  F[u] = ++count;
}

int main() {
  int i, j, u, k, v, n, count;
  
  cin >> n;

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

  count = 0;
  for (i = 0; i < n; ++i) {
    if (!V[i]) dfs(i,n,count);
  }

  for (i = 0; i < n; ++i) {
    cout << i + 1 << ' ' << D[i] << ' ' << F[i] << '\n';
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define MAX 105
#define INF (1<<30)
//#define EZPZ_LEMON_SQUEENZ
using namespace std;

vector<int> M[MAX];
stack<int> s;
int states[MAX][2];
bool vis[MAX];
int n, t;

void dfs(int index)
{
	if (index == n + 1) return;
	vis[index] = true;
	for (int i = 0; i < M[index].size(); i++)
	{
		if (!vis[M[index][i]]) {
			states[M[index][i]][0] = t++;
			dfs(M[index][i]);
			states[M[index][i]][1] = t++;
		}
	}
}

int main()
{
#ifdef EZPZ_LEMON_SQUEENZ
	freopen("D:\\in.txt", "r", stdin);
	freopen("D:\\out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int b, nn, e;
		cin >> b >> nn;
		for (int j = 1; j <= nn; j++) {
			cin >> e;
			M[b].push_back(e);
		}
	}
	t = 1;
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i]) {
			states[i][0] = t++;
			dfs(i);
			states[i][1] = t++;
		}
	}
	for (int i = 1; i <= n; i++) cout << i << " " << states[i][0] << " " << states[i][1] << endl;
	return 0;
}