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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int N=101;

int n,tt=0;
vii M(N,vi(N,0));
vi color(N,WHITE),d(N),f(N),nt(N,0);

void dfs();
void dfs_visit(int);
int next(int);

int main(){
	int i,j,u,k,v;
	cin>>n;
	loop(i,0,n){
		cin>>u>>k;
		loop(j,0,k){
			cin>>v;
			M[u][v]=1;
		}
	}
	dfs();
}

void dfs(){
	int i;
	loop(i,1,n+1){
		if(color[i]==WHITE){
			dfs_visit(i);
		}
	}
	loop(i,1,n+1){
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
}

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=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;
		}
	}
}

int next(int u){
	int v;
	loop(v,nt[u]+1,n+1){
		nt[u]=v;
		if(M[u][v]){
			return v;
		}
	}
	return -1;
}

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

using namespace std;
int timetime = 0;

void dfs(int cur, vector<vector <int> > &list, vector<int> &d, vector<int> &f) {
		d[cur] =timetime;
		timetime +=1;
    for(int i = 0; i < list.size();i++){
      vector<int>::iterator it = list[cur].end();
	  vector<int>::iterator hoge = find(list[cur].begin(),list[cur].end(),i);
      if(d[i] == 0 && (hoge != it ) ){
        dfs(i,list,d,f);
      }
    }
    f[cur] = timetime;
    timetime +=1;
}

int main() {
  int np;
  int k,t,x;
  cin >> np ;
 
  vector <vector <int> > list(np);
  for(int i = 0;i<np;i++) {
    cin >> k;
    cin >> t;
    for(int j = 0; j < t ;j++) {
      cin >>x;
      list[k-1].push_back(x-1);
    }
  }
  vector <int> d(np,0);
  vector <int> f(np,0);
  dfs(0,list,d,f);
  for(int i = 0;i < np; i++){
    cout << i+1 <<" "<<d[i]+1 <<" "<<f[i]+1<<endl;
  }


  return 0;
}

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

struct time_check {
    int find_time, end_time;
};

int main() {
    int G[101][101] = {0};
    time_check t[101];

    for (int i = 1; i <= 100; i++) t[i].end_time = 0;

    stack<int> S;
    int n, u, v, k, elapsed=1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }
    S.push(1);
    t[1].find_time = 1;
    while (! S.empty()) {
        elapsed++;
        u = S.top();
        for (int i = 1; i <= n + 1; i++) {
            if (G[u][i] == 1 && t[i].end_time == 0) {
                t[i].find_time = elapsed;
                G[u][i] = 0;
                S.push(i);
                break;
            }
            if (i == n + 1) {
                t[u].end_time = elapsed;
                S.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << t[i].find_time << " " << t[i].end_time << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

void dfs_visit(int u){
    
    color[u] = GRAY;
    d[u] = ++tt;
    for(int v = 0; v < n; v++){
        if(M[u][v] == 0) continue;
        else if(color[v]== WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;

    f[u] = ++tt;
}



int main(){
    int u;
    int v;
    int k;



    scanf("%d",&n);

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


    for(int i=0; i<n; i++){
        scanf("%d",&u);
        scanf("%d",&k);
        for(int j=0; j<k; j++){
            scanf("%d",&v);

            M[u-1][--v] = 1;
        }
        
    }

    tt = 0;

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

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

    return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;

int G[110][110];
bool seen[110];
int d[110];
int f[110];
int N;
int t = 1;

void dfs( int s ){
    seen[s] = 1;
    d[s] = t++;
    for( int i = 0; i < N; i++ ){
        if( G[s][i] && !seen[i] ){
            dfs( i );
        }
    }
    f[s] = t++;
}

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--;
            G[u][v] = 1;
        }
    }

    for( int i = 0; i < N; i++ ){
        if( !seen[i] ){
            dfs( i );
        }
    }

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