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;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
int t=0;
void dfs(int n,std::vector<int>& d,std::vector<int> &f,std::vector<int>& k,std::vector<int> &al,Graph g){
    if(al[n]==-1){
       // std::cout << n << std::endl;
       al[n]=0;
        ++t;
        d[n]=t;
        erep(i,g[n]){
            
            dfs(i,d,f,k,al,g);
        }
        t++;
        f[n]=t;
        
    }
}

int main(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int>>  g(n);
    std::vector<int> d(n,-1),f(n,-1),k(n,-1),al(n,-1);
    rep(i,n){
        int dd;
        std::cin >> dd;
        dd--;
        std::cin >> k[dd];
        
        rep(j,k[dd]){
            int ddd;
            std::cin >> ddd;
            ddd--;
            g[dd].pb(ddd);
        }
    }
    rep(i,n){
        if(al[i]==-1)dfs(i,d,f,k,al,g);
    }
    //std::cout << n << std::endl;
    rep(i,n){
 //       std::cout << i+1 << std::endl;
        pppri(i+1,d[i],f[i]);
    }
}

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

static const int MAX_NUM = 101;

static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void DSF(int* matrix, int num)
{
    int i;
    int ttime = 0;
    int stime[MAX_NUM+1] = {0};
    int etime[MAX_NUM+1] = {0};
    int state[MAX_NUM+1] = {0};
    stack<int> S;
    int target, next;
    int *tmp;

    S.push(1);
    ++ttime;
    stime[1] = ttime;
    state[1] = NOW_VISIT;

    while (S.empty() == false) {
        target = S.top();
        for (i = 1; i <= num; i++) {
            tmp = matrix + MAX_NUM * target + i;
            if ((*tmp == 1) && (state[i] == NO_VISIT)) {
                *tmp = 2;
                S.push(i);
                ++ttime;
                stime[i] = ttime;
                state[i] = NOW_VISIT;
                break;
            }
        }

        if (i == num + 1) {
            S.pop();
            ++ttime;
            etime[target] = ttime;
            state[target] = END_VISIT;
        }
    }

    for (i = 1; i <= num; i++) {
        printf("%d %d %d\n", i, stime[i], etime[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int elem;
    int nume;
    int tmp;
    int matrix[MAX_NUM][MAX_NUM] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d %d", &elem, &nume);
        for (j = 0; j < nume; j++) {
            scanf("%d", &tmp);
            matrix[elem][tmp] = 1;
        }
    }

    DSF(&matrix[0][0], num);

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 

int n,t;
vector<int>G[101];
int d[101],f[101];
bool used[101];

void dfs(int v){
  used[v]=true;
  d[v]=++t;
  rep(i,G[v].size()){
    int e=G[v][i];
    if(used[e]==false)dfs(e);
  }
  f[v]=++t;
}

int main(){
  cin>>n;
  rep(i,n){
    int u,k;
    cin>>u>>k;
    u--;
    rep(j,k){
      int v;
      cin>>v;
      v--;
      G[u].push_back(v);
    }
  }
  rep(i,n)if(used[i]==false)dfs(i);
  rep(i,n)cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  return 0;
}