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 <vector>
using namespace std;

vector<int> G[100];
pair<int, int> T[100];
const int Inf = 10000*100000+100;
int timer = 1;

int main() {
  void dfs(int cur);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int l = 0; l < k; l++) {
      int v;
      cin >> v;
      G[i].push_back(v - 1);
    }
    T[i] = make_pair(Inf, Inf);
  }
  for (int i = 0; i < n; i++) {
    if (T[i].first == Inf) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << T[i].first << " " << T[i].second << endl;
  }
}

void dfs(int cur) { // cur を訪問
  // cur の訪問時刻を記録
  T[cur].first = timer;
  timer += 1;
  // 動作確認用表示
  for (int dst : G[cur]) { // 全ての節点 dst について
    if (T[dst].first == Inf)
    { // cur から dst に辺があり，dst を未訪問なら
      dfs(dst);
    }
  }
  T[cur].second = timer;
  timer += 1;
}

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

int n;
bool G[110][110];
int d[110], f[110], timer;
bool seen[110];

void dfs(int now){
    d[now] = timer;

    seen[now] = true;

    for(int to=1; to<=n; ++to){
        if(G[now][to] == true && seen[to] == false){
            ++timer;
            dfs(to);
        }
    }

    ++timer;
    f[now] = timer;

}

int main(){
    cin >> n;
    for(int i=0; i<n; ++i){
        int u,k; cin >> u >> k;
        for(int j=0; j<k; ++j){
            int v; cin >> v;
            G[u][v] = true;
        }
    }

    timer = 0;
    for(int i=1; i<=n; ++i){
        if(seen[i] == false){
            ++timer;
            dfs(i);
        }
    }

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

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

int t=1;
int n;
int d[101],f[101];
int v[101];
vector<int> edges[101];

void dfs(int cur)
{
    if(d[cur]==-1)
    {
        d[cur]=t;
        v[cur]=1;
        t+=1;
    }
    int dst;
    for(dst=1;dst<=n;dst++)
    {
        int flag=0;
        for(int i=0;i<edges[cur].size();i++)
        {
            if(edges[cur][i]==dst)
				{
					flag=1;
					break;
				}
        }
        if(v[dst]==-1&&flag)
		  dfs(dst);
    }
    if(f[cur]==-1)
    {
        f[cur]=t;
        t+=1;
    }
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int u,k,y;
		cin >> u >> k;
		for(int j=0;j<k;j++)
        {
            cin >> y;
            edges[u].push_back(y);
        }
	}
	for(int i=1;i<=n;i++)
	{
        d[i]=-1;
        f[i]=-1;
        v[i]=-1;
    }
	for(int dst=1;dst<=n;dst++)
        dfs(dst);
	for(int i=1;i<=n;i++)
	   cout << i << ' ' << d[i] <<  ' ' <<  f[i] <<  endl;
}

C++: #include <bits/stdc++.h> 

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

int n;
vi d, f;
vvi G;
int t = 0;

void dfs(int n)
{
    t++;
    d[n] = t;
    for(int i : G[n]) if(d[i] == 0) dfs(i);
    t++;
    f[n] = t;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> n;
    G.resize(n+1);
    d.resize(n+1, 0);
    f.resize(n+1, 0);
    REP(i, n)
    {
        int u, k; cin >> u >> k;
        REP(j, k)
        {
            int v; cin >> v;
            G[u].pb(v);
        }
    }

    REPS(i, n)
    {
        if(d[i] == 0) dfs(i);
    }

    REPS(i, n) cout << i << " " << d[i] << " " << f[i] << endl;
}

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

class vertex{
public:
  vector<vertex*> to;
  bool visited;
  int num;
  int visit_time;
  int leave_time;
  vertex(){
    visited=false;
  }
  void dfs(){
    visited=true;
    visit_time=time();
    for(int i=0; i<to.size(); i++){
      if(!to[i]->visited) to[i]->dfs();
    }
    leave_time=time();
  }

  void print(){
    cout << num << " " << visit_time << " " << leave_time << endl;
  }

private:
  static int time(){
    static int ti=0;
    ti++;
    return ti;
  }
};

int main(){
  int n; cin >> n;
  vertex graph[n+1];

  int v, k, to;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[v].num = v;
    for(int j=0; j<k; j++){
      cin >> to;
      graph[v].to.push_back(&graph[to]);
    }
  }


  for(int v=1; v<=n; v++){
    if(!graph[v].visited) graph[v].dfs();
  }

  for(int v=1; v<=n; v++){
    graph[v].print();
  }
  
  return 0;
}