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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  t = 1;

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

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
int n;
int v,k,tm;
vector<int> graph[105];
int star[105],tend[105];//记录结束和开始
int vis[105];//纪律顶点是否被访问
void dfs(int u,int& deep)
{
    vis[u]=1;//表示该点已经被访问
    star[u]=deep++;
    sort(graph[u].begin(),graph[u].end());//排序
    for(int i:graph[u])
    {
        if(vis[i]==0){dfs(i,deep);}
    }
    tend[u]=deep++;
    return ;
}
int main()
{
    clr(star,0);clr(tend,0);
    clr(vis,0);
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>v>>k;
        while(k--)
        {
            cin>>tm;
            graph[v].push_back(tm);//连接的点
        }
    }
    int deep=1;
    dfs(1,deep);
    for(int i=1;i<=n;++i)
    {
        cout<<i<<" "<<star[i]<<" "<<tend[i]<<endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
static const int MAX = 100;

int adj[MAX][MAX] = {0};
int n;

enum Color {
  WHITE,
  GRAY,
  BLACK,
};

struct node {
  Color color;
  int begin;
  int end;
};

node nodes[MAX];

void paint(int id, Color c) {
  static int time = 1;
  nodes[id].color = c;
  if (c == GRAY)
    nodes[id].begin = time;
  else if (c == BLACK)
    nodes[id].end = time;
  time++;
}

int next(int id) {
  for (int i = 0; i < n; i++) {
    if (adj[id][i] == 1 && nodes[i].color == WHITE) {
      return i;
    }
  }
  return -1;
}

void visit(int id) {
  stack<int> S;
  S.push(id);
  paint(id, GRAY);

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v > -1) {
      paint(v, GRAY);
      S.push(v);
    } else {
      S.pop();
      paint(u, BLACK);
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i++) {
    nodes[i].color = WHITE;
  }
  for (int i = 0; i < n; i++) {
    if (nodes[i].color == WHITE)
      visit(i);
  }
}

void printNode(int i) {
  printf("%d %d %d\n", i+1, nodes[i].begin, nodes[i].end);
}

int main() {
  cin >> n;
  int id, nn, x;
  for (int i = 0; i < n; i++) {
    cin >> id >> nn;
    id--; // 0-based
    for (int j = 0; j < nn; j++) {
      cin >> x;
      x--; // 0-based
      adj[id][x] = 1;
    }
  }

  dfs();

  for (int i = 0; i < n; i++) {
    printNode(i);
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

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

const int N_MAX = 100;

int T = 1;
int d[N_MAX];
int f[N_MAX];
vector<int> v[N_MAX];

struct node{
    vector<int> near;
    int dis;
    int fin;
    bool found = false;
};

void dfs(int idx){
    d[idx] = T;
    ++T;
    rep(i, (int)v[idx].size()){
        int x = v[idx][i];
        if(d[x] == 0) dfs(x);
    }
    f[idx] = T;
    ++T;
}

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

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

int n, t = 0;
int v[100][100];
int d[100], f[100], r[101];

void st(int id) {
	if (!r[id]) {
		r[id]++;
		d[id - 1] = ++t;
		for (int i = 0; i < n; i++)
			if (v[id - 1][i])
				st(i + 1);
		f[id - 1] = ++t;
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

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

	for(int i = 0; i < n; i++)
		st(i + 1);

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

	return 0;
}