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+1)
	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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

bool A[110][110];
int flag[110],in[110],out[110];
int now=1,n;

void dfs(int u){
	flag[u]=1;
	in[u]=now++;
	for(int i=1;i<=n;i++){
		if(flag[i]==0 && A[i][u]==true){
			dfs(i);
		}
	}
	out[u]=now++;
	return ;
}

int main(){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
			A[c][a]=true;
		}
	}
	for(int i=1;i<=n;i++){
		if(flag[i]==0) dfs(i);
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	}
	return 0;
}

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

using namespace std;
int d[101];
int f[101];
int n;
int M[101][101];
int t;
void DFS(int v) {
	t = t + 1;
	d[v] = t;
	for (int j = 1; j < n + 1; j++) {
		if (M[v][j] == 1) {
			if (d[j] == 0) {
				DFS(j);

			}
		}
	}
	t = t + 1;
	f[v] = t;

}

int main() {
	int  u, k, v;//頂点数、頂点の番号、出次数、隣接する頂点の番号
	t = 0;

	cin >> n;



	//初期化
	for (int i = 0; i < 101; i++) {
		d[i] = 0;
		f[i] = 0;
		for (int j = 0; j < 101; j++) {
			M[i][j] = 0;

		}
	}

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


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

	return 0;
}

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

using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int i,int& clock) //??¶????????°?????\???????????¨
{
    clock++;
    Visited[i]=true;
    dTime[i]=clock; //???????????°??¶??´
    for(int j=0;j<Adjacency[i].size();j++)
    {
        if(Visited[Adjacency[i][j]]==true) continue;
        dfs(Adjacency[i][j],clock);
    }
    clock++; //???????????????????¢????
    fTime[i]=clock;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    dfs(1,clock);
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

C++: #include<iostream>

int d[101]={0};
int f[101]={0};
int us[101]={0};
int V[101][101]={0};
int t=1;
int n;

void tansaku(int x)
{
  d[x]=t++;
  us[x]++;
  for(int i=0;i<n;i++){
    if(V[x][i]==1 and us[i]==0){
      tansaku(i);
    }
  }
  f[x]=t++;
}


int main()
{
  int n;
  int u,k,v;
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>u>>k;
    for(int j=0;j<k;j++){
      std::cin>>v;
      V[u-1][v-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(us[i]==0){
      tansaku(i);
    }
  }
  for(int i=0;i<n;i++){
    std::cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100, MAX_K = 100;

int n, u, k, v[MAX_K];

vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
int t = 0;

void dfs(int);

int main() {
    // input
    cin >> n;
    REP(i, n) {
        cin >> u >> k;
        u--;
        REP(j, k) {
            cin >> v[j];
            v[j]--;
            G[u].PB(v[j]);
        }
    }

    // init d
    REP(i, n) d[i] = -1;

    // dfs
    REP(i, n) {
        if (d[i] == -1) dfs(i);
    }

    // output
    REP(i, n) {
        int id = i + 1;
        printf("%d %d %d\n", id, d[i], f[i]);
    }

    return 0;
}

void dfs(int pos) {
    d[pos] = ++t;
    REP(i, G[pos].size()) {
        int to = G[pos][i];
        if (d[to] != -1) continue;
        dfs(to);
    }
    f[pos] = ++t;
    return;
}