Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int dfs(int from, int turn, vector<vector<int>> &tos, set<int> &used, vector<vector<int>> &ans) {
    used.erase(from);
    ans[from][1] = turn;
    for (int to : tos[from]) {
        if (contain(used, to)) {
            turn = dfs(to, turn + 1, tos, used, ans);
        }
    }
    turn++;
    ans[from][2] = turn;
    return turn;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> tos(n);
    rep(i, n) {
        int j, k;
        cin >> j >> k;
        j--;
        rep(l, k) {
            int m;
            cin >> m;
            m--;
            tos[j].push_back(m);
        }
    }

    vector<vector<int>> ans(n, vector<int>(3, 0));

    rep(i, n) sort(tos[i].begin(), tos[i].end());
    set<int> used;
    rep(i, n) used.insert(i);
    int turn = 0;
    while (!used.empty()) turn = dfs(*used.begin(), turn + 1, tos, used, ans);

    rep(i, n) ans[i][0] = i + 1;
    rep(i, n) print_line(ans[i]);
}

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

int main(){
  int n;
  cin >> n;

  vector<int> list[100];

  for(int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for(int j=0;j<k;j++){
      int v;
      cin >> v;
      list[u-1].push_back(v-1);
    }
  }
  
  int d[100],f[100];
  for(int i=0;i<n;i++) d[i]=f[i]=0;

  stack<int> cur;
  cur.push(0);
  d[0]=1;

  for(int t=2;!cur.empty();t++){
    bool fl=false;
    for(vector<int>::iterator it=list[cur.top()].begin();it!=list[cur.top()].end();it++){
      if(d[*it]==0){
        d[*it]=t;
        fl=true;
        cur.push(*it);
        break;
      }
    }
    if(fl) continue;

    f[cur.top()]=t;
    cur.pop();

    if(cur.empty()){
      for(int i=0;i<n;i++){
        if(d[i]==0){
          t++;
          cur.push(i);
          d[i]=t;
          break;
        }
      }
    }
  }

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

  return 0;
}

C++: a

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

int n, u;
int k[101], b[101], d[101], f[101];
int a[101][101];
int t = 1;

void dfs(int v){
    d[v] = t;
    t++;
    b[v]++;
    for(int l=0; l<k[v]; l++){
        if(b[a[v][l]] == 0){
            dfs(a[v][l]);
        }
    }
    f[v] = t;
    t++;
}


int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u >> k[u];
        for(int j=0; j<k[u]; j++){
            cin >> a[u][j];
        }
    }
    for(int v=1; v<=n; v++){
        if(b[v] == 0){
            dfs(v);
        }
        cout << v << " " << d[v] << " " << f[v] << endl;
    }
    return 0;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-12 18:24:44
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-12 18:38:47
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e2+10;

int d[MAXN],f[MAXN],a[MAXN][MAXN],n,cnt,u,v,t,book[MAXN];

void dfs(int x)
{
	if(!d[x])	d[x] = ++cnt;
	for(int i = 1; i <= n; ++i)
	{
		if(a[x][i] && !book[i])
		{
			book[i] = 1;
			dfs(i);
			book[i] = 0;
		}
	}
	f[x] = ++cnt;
	return;
}

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		cin>>u>>t;
		for(int j = 0; j < t; ++j)
		{
			cin>>v;
			a[u][v] = 1;
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i)
	{
		cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
	}
	return 0;
}

C++: #include <iostream>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
        for (int i = 0; i < n; i++) {
            if (adj_matrix[v][i] != 0) {
                dfs(i, n);
            }
        }
        if (f[v] == 0) {
            f[v] = t;
            t++;
        }
    }
}

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

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

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

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

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

    return 0;
}