Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

class Adjl{
private:
	int u;
	int k;
	Adjl **next;
protected:
	int d;
	int f;
public:
	Adjl(int u);
	~Adjl(){ if (next != NULL) delete[] next; }
	void setV(int k, Adjl *vk);
	int depthFirstSearch(int time);
	void print();
};

Adjl::Adjl(int u)
{
	this->u = u;
	k = 0;
	next = NULL;
	d = 0;
	f = 0;
}

void Adjl::setV(int k, Adjl *vk)
{
	if (this->k == 0) next = new Adjl*[k];
	next[this->k] = vk;
	(this->k)++;
}

int Adjl::depthFirstSearch(int time)
{
	time++;
	d = time;
	for (int i = 0; i < k; i++) {
		if (next[i]->d == 0) {
			time = next[i]->depthFirstSearch(time);
		}
	}
	time++;
	f = time;
	return time;
}

void Adjl::print()
{
	cout << u << " " << d << " " << f << endl;
}

int main(void)
{
	int n;
	cin >> n;
	
	Adjl **adjl = new Adjl*[n];
	int check[100] = {0};

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		if (check[i] == 0) {
			adjl[i] = new Adjl(u);
			check[i] = 1;
		}
		check[i] = 1;
		for (int j = 0; j < k; j++) {
			int vk;
			cin >> vk;
			if (check[vk - 1] == 0) {
				adjl[vk - 1] = new Adjl(vk);
				check[vk - 1] = 1;
			}
			adjl[i]->setV(k, adjl[vk - 1]);
		}
	}

	adjl[0]->depthFirstSearch(0);

	for (int i = 0; i < n; i++) {
		adjl[i]->print();
	}

	delete[] adjl;
	return 0;
}

C++: #if 0

#endif

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

vector<int> E[110];
int N;
int D[110], F[110];

int tim = 0;
void dfs(int cur) {
  tim += 1;
  D[cur] = tim;
  for (auto it = E[cur].begin(); it != E[cur].end(); ++it) {
    if (D[*it] == 0) {
      dfs(*it);
    }
  }
  tim += 1;
  F[cur] = tim;
}

int main() {
  cin >> N;
  int c, k;
  for (int i = 1; i <= N; i++) {
    cin >> c >> k;
    int t;
    for (int j = 0; j < k; j++) {
      cin >> t; E[i].push_back(t);
    }
  }
  for (int i = 1; i <= N; i++) {
    D[i] = 0; F[i] = 0;
  }
  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] << endl;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
vector<int> v[200];
int n,t=1;
int d[200],f[200],done[200];

void dfs(int now){
	//cout<<now<<endl;
	d[now]=t;
	t++;
	done[now]=1;
	lp(i,v[now].size()){
		if(done[v[now][i]]==1) continue;
		dfs(v[now][i]);
	}
	f[now]=t;
	t++;
}

signed main(){
	cin>>n;
	lp(z,n){
		int i,c;
		cin>>i>>c;
		lp(j,c){
			int hoge;
			cin>>hoge;
			v[i].push_back(hoge);
		}
	}
	lps(i,1,n+1){
		if(done[i]==0)
			dfs(i);
	}
	lps(i,1,1+n){
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int n;
vector<vector<int>> g(100);

int d[100], f[100];
bool used[100] = {};
int t = 0;

void dfs(int pos){
    d[pos] = ++t;
    used[pos] = true;

    rep(i, g[pos].size()){
        if(used[g[pos][i]])continue;
        dfs(g[pos][i]);
    }

    f[pos] = ++t;
}

int main(){
    cin >> n;

    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            v--;
            g[i].push_back(v);
        }
    }

    rep(i, n){
        if(!used[i])dfs(i);
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

int main(){
  vector<int> G[100];
  stack<int> q;
  vector<int> d(100,200000000),f(100,200000000);
  int n,u,k,v,time=0;
  bool flg;
  
  cin >> n;
  //G.push_back(new vector<int>(,10));
  for (int i=0;i<n;i++){
    cin >> u>> k;
    for (int j=0;j<k;j++){
      cin >> v;
      G[u-1].push_back(v-1);
    }
  }
  for (int vi=0;vi<n;vi++){
    if (d[vi]<=time)continue;
    q.push(vi);
    d[vi]=++time;
    while (!q.empty()){
      u=q.top();
      for (int i=0;i<G[u].size();i++){
	v=G[u][i];
	if (d[v]>time){
	  q.push(v);
	  d[v]=++time;
	  flg=true;
	  break;
	}
      }
      if (!flg){
	q.pop();
	f[u]=++time;
      }else{
	flg=false;
      }
    }
    
  }
  for (int i=0;i<n;i++)
    cout << i+1 <<" "<< d[i]<<" "<<f[i]<<endl;
  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int G[101][101];
bool used[101];
int f[101],s[101];
int cnt=0;
void dfs(int now){
	cnt++;
	s[now]=cnt;
	used[now]=1;
	for(int i=1;i<=100;i++){
	if(G[now][i]&&used[i]==0)dfs(i);
	}
	cnt++;
	f[now]=cnt;
}

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

	for(int j=1;j<=n;j++){
		if(used[j]==0){
		f=0,next=j;
		break;
		}
	}

if(f)break;
else dfs(next);
}
for(int i=1;i<=n;i++){
	printf("%d %d %d\n",i,s[i],f[i]);
}
return 0;
}