Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

vector< vector< int > > adjList;
vector< int > d, f;

void dfs(int id) {
  static int time = 1;
  if (!d[id-1]) {
    d[id-1] = time++;
    for (int i = 0; i < adjList[id-1].size(); i++)
      dfs(adjList[id-1][i]);
    f[id-1] = time++;
  }
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  adjList = vector< vector< int > > (n, vector< int > ());
  d = vector< int > (n, 0);
  f = vector< int > (n, 0);
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      int holder;
      cin >> holder;
      adjList[id-1].push_back(holder);
    }
  }
  for (int i = 0; i < n; i++)
    if (!d[i])
      dfs(i+1);
  for (int i = 0; i < n; i++)
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  return 0;
}

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 <stdio.h>

int time, n;
int d[100], f[100], color[100];

void dfs(int u) {
    color[u] = 1
    d[u] = ++time;
    for (int i=0; i<n; i++) {
        if(M[u][i] && color[i] == 0) {
            dfs(i);
        }
    }
    color[u] = 2;
    f[u] = ++time;
}

void dfs_init(){
    for (int i=0; i<100; i++) color[i] = 0;
    dfs();
}

int main() {
    int u, k, v;
    scanf("%d", &n);
    
    int M[n][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++) {
        scanf("%d %d", &u, &k);
        for (int j=0; j<k; j++) {
            scanf("%d", &v);
            M[u-1][v-1] = 1;
        }
    }
    
    dfs_init();
    
    for (int i=0; i<n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <cstdio>
#include <stack>
#include <vector>
using namespace std;
static const int MAX = 101;
int V, tt;
bool visited[MAX];
int disc[MAX], finish_time[MAX];
vector<int> G[MAX];

void dfs(int current) {
      visited[current] = true;
      disc[current] = ++tt;
      for (int i = 0; i < G[current].size(); i++) {
          int next = G[current][i];
          if (!visited[next]) dfs(next);
      }
      finish_time[current] = ++tt;
}

int main()
{
    int k, source, target;
    tt=0;
    scanf("%d", &V);
    for (int i = 0; i < V; i++) {
        scanf("%d %d", &source, &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &target);
            G[source].push_back(target);
        }
    }

    fill(visited, visited+V+1, 0);
    fill(disc, disc+V+1, 0);
    fill(finish_time, finish_time+V+1, 0);
    for (int i = 1; i <= V; i++) {
        if (!visited[i]) {
            dfs(i);
        }
    }

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

    return 0;
}

C++: /*
** dfs 遍历图
*/

# include <cstdio>
# include <cstring>
# include <stack>
using namespace std;

const int MAX = 100 + 2;

int g[MAX][MAX], d[MAX], f[MAX], c[MAX], n, t;

void init() {
    memset(g, 0, sizeof(g));
    memset(d, 0, sizeof(d));
    // memset(f, 0, sizeof(f));
    memset(c, 0, sizeof(c));
    scanf("%d", &n);
    int u, v, k;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &u, &k);
        while (k--) {
            scanf("%d", &v);
            g[u][v] = 1;
        }
    }

    t = 0;
}

void dfs(int u) {
    t++;
    stack<int> s;
    s.push(u);
    int node;
    d[u] = t;
    c[u] = 1;

    while(!s.empty()) {
        t++;
        node = s.top();
        int p = 1;
        for (; p <= n; p++) {
            if (g[node][p] != 0 && c[p] == 0) {
                s.push(p);
                d[p] = t;
                c[p] = 1;
                break;
            }
        }
        if (p > n) {
            f[node] = t;
            s.pop();
        }
    }
}

void solve() {
    init();
    for (int i = 1; i <= n; i++) {
        if (c[i] == 0) {
            dfs(i);
        }
    }
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}