Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

C++: // -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_11_B: Depth First Search

#include <algorithm>
#include <cstdio>
#include <stack>
#include <utility>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  std::pair<int, int>* const visited_;
  uint time_;
  
public:
  Graph(uint n) : n_(n),
                  g_(new uint[(n_*n_)]),
                  visited_(new std::pair<int, int>[n_])
  {
    std::fill(g_, g_+(n_*n_), 0u);
  }

  ~Graph()
  {
    delete[] g_;
    delete[] visited_;
  }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  std::pair<int, int>* visited() const { return visited_; }

  void dfs()
  {
    init_visited();
    for (auto i = 0u; i < n_; ++i) {
      inner_dfs(i);
    }
  }

private:
  void init_visited()
  {
    time_ = 0u;
    for (auto i = 0u; i < n_; ++i) {
      visited_[i].first = -1;
    }
  }

  void inner_dfs(uint i)
  {
    if (visited_[i].first != -1) {
      return;
    }
    visited_[i].first = time_++;
    for (auto j = 0u; j < n_; ++j) {
      auto k = (*this)[i][j];
      if (k) {
        inner_dfs(j);
      }
    }
    visited_[i].second = time_++;
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u", &v);
      g[u-1][v-1] = 1;
    }
  }

  g.dfs();
  auto visited = g.visited();
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %d %d\n", i+1, visited[i].first+1, visited[i].second+1);
  }
}

// eof

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
//#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	if (book[u] == white) return; 
	else
		if (book[u] == black)
		{
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
				dfs(*it-1);
			book[u] = white;
			t[u][1] = ++tot;
		}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u,k,v;
		scanf("%d%d", &u,&k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	dfs(0);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d\n", i + 1, t[i][0], t[i][1]);
	}
	return 0;
}

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

int n,M[105][105],d[105],f[105],tt,P[105],nt[105];

int next(int u){
	for(int v=nt[u];v<n;v++){
		nt[u]=v+1;
		if(M[u][v]){
			return v;
		}
	}
	return -1;
}
void dfs_visit(int r){
	for(int i=0;i<n;i++){
		nt[i]=0;
	}
	stack<int> s;
	s.push(r);
	P[r]=1;
	tt++;
	d[r]=tt;
	while(s.size()!=0){
		int u= s.top();
		int v=next(u);
		if(v!=-1){
			if(P[v]==0){
				P[v]=1;
				tt++;
				d[v]=tt;
				s.push(v);
			}
		}
		else{
			P[u]=2;
			tt++;
			f[u]=tt;
			s.pop();
		}
	}
}

void dfs(){
	for(int i=0;i<105;i++){
		d[i]=f[i]=P[i]=0;
	}
	tt=0;
	for(int i=0;i<n;i++){
		if(P[i]==0){
			dfs_visit(i);
		}
	}
	for(int i=0;i<n;i++){
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}
}

int main() {
	cin>>n;
	int u,k,v;
	for(int i=0;i<105;i++){
		for(int j=0;j<105;j++){
			M[i][j]=0;
		}
	}
	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;
		}
	}
	dfs();
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define MAX 101

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll visited[MAX], d[MAX], f[MAX], tt = 0;
vector<int> G[MAX];

void dfs(int u) {
  d[u] = ++tt;
  visited[u] = 1;
  rep(i, G[u].size()) {
    if(visited[G[u][i]] == 0) dfs(G[u][i]);
  }
  f[u] = ++tt;
}

signed main() {
	ll n;
  cin >> n;
  for(int i = 1; i <= n; i++) visited[i] = 0;
  rep(i, n) {
    ll u, k;
    cin >> u >> k;
    rep(j, k) {
      ll v;
      cin >> v;
      G[u].pb(v);
    }
  }

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

	return 0;
}

C++: // ALDS1_11_B.cpp
// Graph I - Depth First Search

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

struct Vertex
{
    int id;
    vector<int> adjList;
    int d = 0;
    int f = 0;
};

int cnt = 0;

void dfs(vector<Vertex> &V, int n, int i)
{
    if (V[i].d != 0 && V[i].f != 0)
        return;
    int len = V[i].adjList.size();
    V[i].d = ++cnt;

    for (int j = 0; j < len; j++) {
        int next = V[i].adjList[j];
        if (V[next].d == 0) {
            // V[next].d = ++cnt;
            dfs(V, n, next);
            //V[next].f = ++cnt;
        }
    }
    V[i].f = ++cnt;
}

int main()
{
    int n;
    cin >> n;
    vector<Vertex> V(n);
    int id;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> id >> num;
        V[id-1].id = id-1;
        int tmp;
        for (int j = 0; j < num; j++) {
            cin >> tmp;
            V[id-1].adjList.push_back(tmp-1);
        }
    }
    for (int i = 0; i < n; i++)
        dfs(V, n, i);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i + 1, V[i].d, V[i].f);
    }
    return 0;
}

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

int main(){

  int vertex_num, time;
  cin >> vertex_num;
  vector<vector<int>> adjacent_graph;
  adjacent_graph.resize(101);
  int discover[101],finished[101];
  rep(i,101) discover[i] = finished[i] = -1;

  rep(i,vertex_num){
    int vertex, adjacent_num,tmp;
    vector<int> input_graph;
    cin >> vertex >> adjacent_num;
    rep(j,adjacent_num){
      cin >> tmp;
      input_graph.emplace_back(tmp);
    }
    adjacent_graph[vertex] = input_graph;
  }

  stack<int> stk;
  time = 0;
  for(int i=1;i<=vertex_num;i++){
    if(discover[i] == -1){
      stk.emplace(i);
      discover[i] = ++time;
    }
    while(!stk.empty()){
      int now = stk.top();
        bool hasnext = false;
        rep(j,adjacent_graph[now].size()){
          int next = adjacent_graph[now][j];
          if(discover[next] == -1) {
            discover[next] = ++time;
            stk.emplace(next);
            hasnext = true;
            break;
          }
        }
        if(!hasnext){   
        finished[now] = ++time;
        stk.pop();
        }
    }
  }

  for(int i =1;i<=vertex_num; i++){
    cout << i << " " << discover[i] << " " << finished[i] << endl;
  }

  return 0;
}