Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][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;
      adj[u-1][v-1] = 1;
    }
  }

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

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

    t++;
  }

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

}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,u,k,p,d[105],f[105],tt=0;
bool adm[105][105],se[105];

void makemap()
{
    memset(adm,false,sizeof(adm));
    memset(se,true,sizeof(se));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
}

void dfs(int p)
{
    d[p]=++tt;
    se[p]=false;
    for(int i=1;i<=n;i++)
        if(adm[p][i]&&se[i])dfs(i);
    f[p]=++tt;
}

int main()
{
    makemap();
    for(int i=1;i<=n;i++)if(se[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time = 1) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) {
		if (!checked[adjacent[now][i]]) {
			time = dfs(adjacent[now][i], time + 1);
		}
	}
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(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;
			adjacent[u - 1].push_back(v-1);
		}
	}
	
	int time = dfs(0, 1)+1;
	for (int i = 0; i < n; i++) {
		if (!checked[i])time = dfs(i, time)+1;
	}
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
	}

}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

vector<vector<size_t>> g;
vector<size_t> gs;
vector<size_t> gf;
stack<size_t> st;

size_t dfs(size_t i, size_t t) {
	st.push(i);
	while (!st.empty()) {
		auto j = st.top();
		vector<size_t>& l = g.at(j);
		if (gs.at(j) != 0) {
			if (gf.at(j) == 0)
				gf.at(j) = ++t;
			st.pop();
			continue;
		}
		gs.at(j) = ++t;
		for (ll k = l.size() - 1; k >= 0; --k) {
			auto n = l.at(k);
			if (gs.at(n) == 0) {
				st.push(n);
			}
		}
	}
	return t;
}

int main() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	size_t n;
	cin >> n;
	g.resize(n);
	gs.resize(n);
	gf.resize(n);

	REP(i, n) {
		size_t u, k;
		cin >> u >> k;
		u -= 1; // 0 base
		g.at(u).resize(k);
		REP(j, k) {
			cin >> g.at(u).at(j);
			g.at(u).at(j)--;
		}
	}
	size_t t = 0;
	for (;;) {
		size_t target = INF;
		REP(i, n) {
			if (gs.at(i) == 0) {
				target = i;
				break;
			}
		}
		if (target == INF) break;
		t = dfs(target, t);
	}
	
	REP(i, n) {
		cout << i + 1 << " " << gs.at(i) << " " << gf.at(i) << ::endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !start[graph[num][i]] && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>


class Graph {
public:
    std::vector<int> d, v;
    std::vector<std::vector<int>> arr;
    int n;
    int tp = 1;

    Graph(int n) : n(n) {
        d = std::vector<int>(n, 0);
        v = std::vector<int>(n, 0);
        arr = std::vector<std::vector<int>>(n);
    }
    
    void depth_search(int i) {
        if (d[i] == 0) {
            d[i] = tp;
            tp++;
            for (auto j : arr[i]) {
                depth_search(j - 1);
            }
            v[i] = tp;
            tp++;
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i + 1 << " " << d[i] << " " << v[i] << std::endl;
        }
    }
};


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

    Graph graph(n);
    
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> vs(k);
        
        for (int i = 0; i < k; i++) {
            std::cin >> vs[i];
        }
        graph.arr[u - 1] = vs;
    }

    for (int i = 0; i < n; i++) {
        graph.depth_search(i);
    }

    graph.print();

}

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> d(101, -1), f(101, -1);
vector<vector<int> > c;

int n, u, k, v;
int dfs(int node, int time) {
    d[node] = time;
    for(int i=0; i<n; ++i) {
        if(c[node][i]==1&&d[i]==-1) time = dfs(i, time+1);
    }
    time++;
    f[node] = time;
    return time;
}

int main() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        vector<int> tmp(100, 0);
        for(int j=0; j<k; ++j) {
            cin >> v;
            tmp[v-1] = 1;
        }
        c.push_back(tmp);
    }

    bool isFinished = false;
    int node = 0;
    int time = 1;
    while(isFinished==false) {
        time = dfs(node, time);
        isFinished = true;
        for(node=0; node<n; node++) {
            if(d[node]==-1) {
                isFinished=false;
                break;
            }
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}