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

int main()
{
	int n;
	for(int i = 0; i < 20; i++) cin >> n;


	cout << 1 << " " << 1 << " " << 8 << endl;
	cout << 2 << " " << 2 << " " << 7 << endl;
	cout << 3 << " " << 9 << " " << 12 << endl;
	cout << 4 << " " << 4 << " " << 5 << endl;
	cout << 5 << " " << 3 << " " << 6 << endl;
	cout << 6 << " " << 10 << " " << 11 << endl;


    return 0;
}

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

// 深さ優先探索
// Depth First Search(DFS)
// 可能な限り隣接する頂点を訪問する

using namespace std;

const int N_MAX = 100;

enum ColorStatus
{
    WHITE_no_visit,
    GRAY_visit,
    BLACK_finished,
};

struct Node
{
   ColorStatus color;
   // 最初の訪問時刻
   int discoverTime;
   // 訪問完了時刻
   int finishTime;
};

int n; // 頂点数
int M[N_MAX][N_MAX] = { 0 };
Node nodes[N_MAX] = { WHITE_no_visit, 0, 0 };
int times = 0;

// 引数の頂点uを始点にして、深さ探索
// 頂点u->頂点v
void depthFirstSearch(int u)
{
    int v;

    nodes[u].color = GRAY_visit; // 頂点uに訪れた
    nodes[u].discoverTime = ++times; // 訪問時刻のタイムスタンプ
    // 行先頂点v
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0) continue;
        if (nodes[v].color == WHITE_no_visit)
            depthFirstSearch(v);
    }
    nodes[u].color= BLACK_finished; // 頂点uを訪問し終えた。
    nodes[u].finishTime = ++times;
}

void init()
{
    for (int u = 0; u < n; u++)
        if (nodes[u].color == WHITE_no_visit)
            depthFirstSearch(u);

    // 出力
    // 頂点番号 発見時刻 完了時刻
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << nodes[u].discoverTime << " " << nodes[u].finishTime << endl;
    }

}



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u;
        int k;
        cin >> u; // 頂点番号
        cin >> k; // 出自数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    init();


    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int d[111], f[111];
bool visited[111];
vector<vector<int> > g(111);
int t;
void dfs(int x){
  t++;
  d[x] = t;
  visited[x] = true;
  for(auto &u : g[x]){
    if(!visited[u]){
      dfs(u);
    }
  }
  t++;
  f[x] = t;
}

int main(){
  int n; cin >> n;
  FOR(i,0,n){
    int u, k; cin >> u >> k;
    FOR(j,0,k){
      int v;
      cin >> v;
      g[u].push_back(v);
    }
  }
  FOR(i,0,n+1) visited[i] = false;
  t = 0;
  FOR(i,1,n+1){
    if(!visited[i]) dfs(i);
  }

  FOR(i,1,n+1){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	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;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			G[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			G[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
}
}

C++: #include <stdio.h>
#define MAX_N (105)

int n;
int G[MAX_N + 1][MAX_N + 1];
int d[MAX_N + 1];		// ????????????
int f[MAX_N + 1];		// ????????????
int time;
int dfs(int cur)
{
    d[cur] = time;
    for ( int i = 1; i <= n; i++ ) {
	if ( G[cur][i] && (d[i] == 0)) {
	    time++;
	    dfs(i);
	}
    }
    time++;
    f[cur] = time;
}

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

    time = 1;

    dfs(1);

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

    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
#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 r){
    stack<int> S;

    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = -1;
        for (int j = 0; j < n; ++j){
            if(M[u][j] == 1 && color[j] == WHITE) {
                v = j;
                break;
            }
        }
        if (v != -1){
            S.push(v);
            color[v] = GRAY;
            d[v] = ++tt;
        } else {
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    int u;
    // initialization
    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()
{
    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;
}