Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <bits/stdc++.h>
using namespace std;
#define WHITE 0
#define GLAY 1
#define BLACK 2

// 頂点の個数
int n;
// 隣接行列
vector<vector<int> > M(100, vector<int>(100, 0));
// 頂点の状態を格納する配列
vector<int> color(100, WHITE);
// 発見時刻を格納する配列
vector<int> d(100);
// 完了時刻を格納する配列
vector<int> f(100);
// 時刻
int tt = 0;

// 再帰的にu(WHITEと仮定)をスタートして探索
void dfs_visit(int u)
{
  // uの状態を訪問済みにする
  color.at(u) = GLAY;
  // uの発見時刻を記録
  d.at(u) = ++tt;
  // uの隣接頂点(小さい順に)探索
  for (int v = 0; v < n; v++)
  {
    if (M.at(u).at(v) == 0)
    {
      // vがuの隣接頂点でないとき
      // このループをスキップ
      continue;
    }
    if (color.at(v) == WHITE)
    {
      // vがuの隣接頂点であり、かつ未発見のとき
      // vをスタートとして探索
      dfs_visit(v);
    }
  }
  // uの隣接頂点の状態が全て完了になっているのでuの状態も完了にする
  color.at(u) = BLACK;
  // uの完了時刻を記録
  f.at(u) = ++tt;
}

// 全ての頂点を探索
void dfs()
{
  for (int i = 0; i < n; i++)
  {
    if (color.at(i) == WHITE)
    {
      dfs_visit(i);
    }
  }
}

int main()
{
  cin >> 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--;
      M.at(u).at(v) = 1;
    }
  }

  dfs();

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

C++: #include <stdio.h>

#define N 101

int color[N];
int n, G[N][N],f[N],d[N],time;

void visit(int);

int main(){
  int i,j,v,vnext,k;
 
  scanf("%d",&n);

  for(i=0;i<n;i++){
    color[i] = 0;
    for(j=0;j<n;j++) {
      G[i][j] = 0;
    }
  }

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

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

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

void visit(int u){

  int i; 
  color[u]=1;
  d[u]= ++time;
  for(i=0; i<n; i++){
    if(G[u][i] == 1){
      if(color[i] == 0)visit(i);
    }
  }

  color[u]= 2;
  f[u]=++time;
}

C++: #include<stdio.h>
 
#define MAX 101
#define WHITE -1
#define GRAY 0
#define BLACK 1
 
int n,t;
int color[MAX],d[MAX],f[MAX],Adj[MAX][MAX];
 
dfs(){
  int i;
 
  for(i=0;i<n;i++) color[i]=WHITE;
  t=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE) visit(i);
  }
}
 
visit(int r){
  int i;
 
  color[r]=GRAY;
  d[r]=++t;
 
  for(i=0;i<n;i++){
    if(Adj[r][i]==1 && color[i]==WHITE) visit(i);
  }
 
  color[r]=BLACK;
  f[r]=++t;
}
 
int main(){
  int i,u,k,j,v;
 
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){ 
      Adj[i][j]=0;
    }
  }
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u-1][v-1]=1;
    }
  }
 
  dfs();
 
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
 
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define EXIST 1
#define TODO 1
#define DONE 0
int graph[200][200];
int used[200];
int disc[200];
int fin[200];
int n;
int elapsed;

void dfs(int pos) {
  disc[pos] = ++elapsed;
  used[pos] = DONE;
  for (int i = 0; i < n; i++) {
    if (graph[pos][i] == EXIST && used[i] == TODO) {
      dfs(i);
    }
  }
  fin[pos] = ++elapsed;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, k, v; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      graph[u-1][v-1] = EXIST;
    }
    used[i] = TODO;
  }
  for (int i = 0; i < n; i++) {
    if (used[i] == TODO) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << disc[i] << " " << fin[i] << endl; 
  }
}

C++: #include<iostream>
#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",u+1,d[u],f[u]);
    }
}

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

    dfs();
    return 0;
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int** gmtrx;
int* d, *f;
int t, n;

class Stack{
public:
	Stack(int num):head(0){
		s = new int [num];
		for(int i=0; i<num; ++i){
			s[i] = 0;
		}
	}
	~Stack(){ delete[] s; }
	void push_back(int vtx){
		s[head++] = vtx;
	}
	int pop_back(){
		--head;
		int tmp = s[head];
		s[head] = 0;
		return tmp;
	}
	int back(){
		if(head<=0) return -1;
		return s[head-1];
	}
private:
	int head;
	int* s;
};


int main()
{
	scanf("%d",&n);

	gmtrx = new int*[n];
	d = new int [n]; //discovery
	f = new int [n]; //finish
	Stack st(n);

	for(int i=0; i<n; ++i){
		gmtrx[i] = new int[n];
		for(int j=0; j<n; ++j){
			gmtrx[i][j] = 0;
		}
		d[i] = 0;
		f[i] = 0;
	}

	for(int i=0; i<n; ++i){
		int v, num, a;
		scanf("%d %d",&v,&num);
		--v;
		for(int j=0; j<num; ++j){
			scanf("%d",&a);
			--a;
			gmtrx[v][a] = 1;
		}
	}

	for(int i=0; i<n; ++i){
		int vtmp=i;
		if( d[vtmp]!= 0) continue;
		st.push_back(vtmp);
		vtmp=0;
		while(st.back()!=-1){
			if(d[st.back()]==0){
				++t;
				d[st.back()] = t;
			}
			else if(f[st.back()]!=0){
				vtmp = st.pop_back();
				++vtmp;
				continue;
			}
			for(int j=vtmp; j<=n; ++j){
				if(j==n){
					++t;
					f[st.back()] = t;
					vtmp = st.pop_back();
					++vtmp;
					break;
				}
				if(gmtrx[st.back()][j]){
					if(d[j]==0) st.push_back(j);
					else continue;
					break;
				}
			}
		}
	}

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

	for(int i=0; i<n; ++i){
		delete[] gmtrx[i];
	}
	delete[] gmtrx;
	delete[] d;
	delete[] f;

	return 0;
}