Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <bitset>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct dd{
    int d,f;
    dd(){
        d=0;
        f=0;
    }
};
bool data[101][101]={};
void f1(dd*,int,int&,int);

int main()
{
    int N,M,num1,num2;
    dd ddata[101]={};
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>num1;
        cin>>M;
        for(int j=0;j<M;j++){
            cin>>num2;
            data[num1][num2]=true;
        }
    }
    int time=1;
    for(int i=1;i<=N;i++){
        if(!ddata[i].d)f1(ddata,i,time,N);
    }
    for(int i=1;i<=N;i++){
        cout<<i<<' '<<ddata[i].d;
        if(ddata[i].d){
            cout<<' '<<ddata[i].f;
        }
        cout<<endl;
    }
}
void f1(dd* ddata,int num,int& time,int N)
{
    if(!ddata[num].d)ddata[num].d=time++;
    else return;
    data[num][num]=false;
    for(int i=1;i<=N;i++){
        if(data[num][i]){
            data[num][i]=false;
            data[i][num]=false;
            f1(ddata,i,time,N);
        }
    }
    ddata[num].f=time++;
}

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

#define MAX 101

using namespace std;

int visited[MAX],d[MAX],f[MAX];
int tt=0;
vector<int> G[MAX];

void dfs(int u){
  d[u]=++tt;
  visited[u]=1;
  for(int i=0;i<G[u].size();i++){
    if(visited[G[u][i]]==0) dfs(G[u][i]);
  }
  f[u]=++tt;
}

int main(){
  int n; cin >> n;
  for(int i=1;i<=n;i++) visited[i]=0;
  for(int i=0;i<n;i++){
    int u,k; cin >> u >> k;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }
  dfs(1);
  for(int i=1;i<=n;i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
}

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

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

int next(int u) {
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		return v;
	}
	return -1;
}

void dfs_visit(int u) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(u);
	color[u] = BLACK;
	f[u] = ++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; 
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	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;
      }	
	}
	cin >> u >> k ;
	u--;
	for(int i = 0; i < k; i++ ) {
	   cin >> v;
	   v--;
	   M[u][v] = 1;	
	}	
	
	dfs();
	
	return 0;
}

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

struct vertex
{
	int id;
	int discover;
	int finish;
	bool flag;
};

static int time = 1;

void DFS(int **arr, int n, int u , vertex *ver)
{
	ver[u - 1].flag = 1;
	ver[u - 1].discover = time;
	time++;
	for (int i = 0; i < n; i++)
	{
		if (u - 1 == i)
			continue;
		if (arr[u - 1][i] == 1 && ver[i].flag == 0)
		{
			DFS(arr, n, i + 1, ver);
			time++;
		}
	}
	ver[u - 1].finish = time;
}


int main()
{
	int n = 0;
	while (cin >> n)
	{
		int **arr = new int*[n];
		vertex *ver = new vertex[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = new int[n];
			for (int j = 0; j < n; j++)
			{
				arr[i][j] = 0;
			}
			ver[i].id = i + 1;
			ver[i].flag = 0;
		}
		for (int i = 0; i < n; i++)
		{
			int u = 0;
			int k = 0;
			int v = 0;
			cin >> u >> k;
			while (k--)
			{
				cin >> v;
				arr[u - 1][v - 1]++;
			}
		}
		for (int i = 0; i < n; i++)
		{
			if(ver[i].flag == 0)
				DFS(arr, n, i + 1, ver);
		}
		for (int i = 0; i < n; i++)
		{
			cout << ver[i].id << " " << ver[i].discover << " " << ver[i].finish << endl;
		}
		time = 1;
	}

	return 0;
}

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

int visit[100],end[100],a[100][100];
int t,N,u,k,col;

void rist_to_mat(int N) {
	for(int l=0; l<N; ++l) {
		cin >> u >> k;
		for (int i=0; i<k; ++i) {
			cin >> col;
			a[u-1][col-1] = 1;
		}
	}
}

void dfs(int cur,int N) {
	t += 1;
	visit[cur] = t;
	for(int dst=0; dst<N; ++dst) {
		if(a[cur][dst] == 1 && visit[dst] == 0) {
			dfs(dst,N);
		}
	}
	t += 1;
	end[cur] = t;
}

int main() {
	cin >> N;
	rist_to_mat(N);
	for(int i=0; i<N; ++i) {
		if(visit[i] == 0) dfs(i,N);
	}
	for(int i=0; i<N; ++i) {
		cout << i+1 << ' ' << visit[i] << ' ' << end[i] << endl;
	}
}