Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
vector<bool>seen(1000,false);
vector<pair<int,int>>ans(1000);
vector<int>first_order(1000,10e7),last_order(1000,10e7);
void dfs(const vvll &gura, int v, int& now) {
    first_order[v] = min(first_order[v],now++);

    seen[v] = true; 
    for (auto next_v : gura[v]) { 
        if (seen[next_v]) continue;
        dfs(gura, next_v, now);
    }

    last_order[v] = min(last_order[v],now++);
}
int main(){
    int n;
    cin >> n;
    vvll gura(n);
    for(int i=0;i<n;i++){
        int ww; cin >>ww;
        int w;
        cin >> w;
        for(int j=0;j<w;j++){
            int d;
            cin >> d;
            gura.at(i).push_back(d-1);
        }
    }
    int now = 1;
    for(int i=0;i<n;i++){
        if(seen[i])continue;
    dfs(gura,i,now);
    }
    for(int i=0;i<n;i++){
        cout << i+1<<" "<< first_order[i]<<" "<<last_order[i]<<endl;
    }
}

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

using namespace std;

int n, d[110], f[110], t = 0;
set<int> st;
vector<int> g[110];

void dfs(int m) {
  t++;
  d[m] = t;
  st.erase(m);
  for(int i = 0; i < g[m].size(); i++) {
    if(d[g[m][i]] == -1) {
      dfs(g[m][i]);
    }
  }
  t++;
  f[m] = t;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    int index, k, v;
    cin >> index >> k;
    for(int j = 0; j < k; j++) {
      cin >> v;
      g[index].push_back(v);
    }
    st.insert(index);
    d[index] = -1;
  }
  while(!st.empty()) {
    auto itr = st.begin();
    dfs(*itr);
  }
  for(int i = 0; i < n; i++)
    cout << i+1 << " " << d[i+1] << " " << f[i+1] << endl;

  return 0;
}

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

int cnt=1;

void DFS(int k, vector<vector<int> >& V, vector<pair<int,int> >& time) {
	time[k].first=cnt++;
	for(int i=1; i<=(int)V[k].size(); ++i) {
		if(time[V[k][i]].first==-1) {
			DFS(V[k][i],V,time);
		}
	}
	time[k].second=cnt++;
	return;
}

int main() {
	int i,j;
	int n;
	int u,k;
	vector<vector<int> > V;
	vector<pair<int,int> > time;
	scanf("%d",&n);
	V.resize(n+1);
	time.resize(n+1);

	for(i=1; i<=n; ++i) {
		scanf("%d%d",&u,&k);
		V[u].resize(k);
		time[u]={-1,-1};
		for(j=1; j<=k; ++j) {
			scanf("%d",&V[u][j]);
		}
	}
	DFS(1,V,time);
	for(i=1; i<=n; ++i) {
		printf("%d %d %d\n",i,time[i].first,time[i].second);
	}
	return 0;
}

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

using namespace std;

class Node {
public:
	vector<int> rels;
	int id, len, pos, ts1, ts2;
	Node();
	int next();
};

Node::Node() {
	pos = ts1 = ts2 = 0;
}

int Node::next() {
	if (pos >= len) return -1;
	int next = rels[pos];
	pos++;
	return next;
}


void dfs(int idx, Node **graph, stack<int> *stack, int *time) {
	stack->push(idx);
	graph[idx]->ts1 = ++(*time);
	while (stack->size() > 0) {
		int u = stack->top();
		int v = graph[u]->next();
		if (v != -1) {
			if (graph[v]->ts1 == 0) {
				graph[v]->ts1 = ++(*time);
				stack->push(v);
			}
		}
		else {
			graph[u]->ts2 = ++(*time);
			stack->pop();
		}
	}
}

int main() {
	int n, val, time;
	Node *graph[100];
	stack<int> stack;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		graph[i] = new Node();
		cin >> graph[i]->id;
		cin >> graph[i]->len;
		for (int j = 0; j < graph[i]->len; j++) {
			cin >> val;
			graph[i]->rels.push_back(val-1);
		}
	}

	time = 0;
	for (int i = 0; i < n; i++) {
		if (graph[i]->ts1 == 0)
			dfs(i, graph, &stack, &time);
	}


	for (int i = 0; i < n; i++) {
		cout << graph[i]->id << " " << graph[i]->ts1 << " " << graph[i]->ts2 << endl;
	}

	for (int i = 0; i < n; i++)
		delete(graph[i]);


	return 0;	
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N 101
int s[N], f[N], tt = 0, n;
int graph[N][N];

void dfs(int node){
    if(s[node] == 0){
        s[node] = ++tt;
    }else return;
    for(int i = 0; i < n; i++){
        if(graph[node][i]) dfs(i);
    }
    f[node] = ++tt;
}

int main(){
    int u, k, val;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)graph[i][j] = 0;
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++){
            scanf("%d", &val);
            val--;
            graph[u][val] = 1;
        }
    }
    
    for(int i = 0; i < n; i++)dfs(i);
    for(int i = 0; i < n; i++)printf("%d %d %d\n", i + 1, s[i], f[i]);
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxx = 110;
int n, m[maxx][maxx];
int u, num, v;
int d[maxx], f[maxx];
int flag[maxx];
int nowtime = 1;

void dfs(int u) {

	// ??\?????¶??´
	flag[u] = 1;
	d[u] = nowtime++;
	for (int i = 1; i <= n; i++) {
		if (flag[i] == 0 && m[u][i] == 1) {
			dfs(i);
		}
	}
	//????????¶??´
	f[u] = nowtime++;
}

int main()
{

	scanf("%d", &n);
	memset(m, 0, sizeof(m));
	memset(f, 0, sizeof(f));
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &u, &num);
		for (int j = 1; j <= num; j++) {
			scanf("%d", &v);
			m[u][v] = 1;
		}
	}
	
	dfs(1);
	for (int i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
	return 0;
}