Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

C++: #include<iostream>
using namespace std;
const int maxn = 101;
int G[maxn][maxn], n;
int d[maxn], f[maxn], vis[maxn];
int t;
void DFS(int u)
{
    vis[u] = 1;
    d[u] = t++;
    for(int i = 1; i <= n; i++)
        if(vis[i] == 0 && G[u][i] > 0)
            DFS(i);
    f[u] = t++;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j =1; j <= n; j++)
            G[i][j] = 0;

    for(int i = 0; i < n; i++)
    {
        int x, k;
        cin >> x >> k;
        for(int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            G[x][v] = 1;
        }
    }
    t = 1;
    DFS(1);
    for(int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int g[101][102],ch[101][2]={0};

int dfs(int k,int n){
  ch[n][0]=k;
  //cout<<k<<n<<"<--"<<endl;/////////
  for(int i=1;i<=g[n][0];i++){
    if(ch[g[n][i]][0]==0){
      k=dfs(k+1,g[n][i]);
    }
  }
  ch[n][1]=k+1;
  return k+1;
}

int main(){
  int a,b,c,d;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b>>c;
    g[b][0]=c;
    for(int j=1;j<=c;j++){
      cin>>d;
      g[b][j]=d;
    }
  }
  dfs(1,1);
  for(int i=1;i<=a;i++){
    cout<<i<<" "<<ch[i][0]<<" "<<ch[i][1]<<endl;
    
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
//_______

vector <int> G[102];
pii d[102];
int tt;
int N;

void dfs(int u)
{
   d[u].fi = ++tt;
   rep(i, G[u].size()){
      if( d[ G[u][i] ].fi == 0 )dfs( G[u][i] );
   }
   d[u].se = ++tt;
   return ;
}

void slv()
{
   tt = 0;
   reps(i, 1, N)
      if( d[i].fi == 0 ) dfs(i);
   reps(i, 1, N)
      cout << i << ' ' << d[i].fi << ' ' << d[i].se << '\n';
}

signed main()
{
   FAST();
   int u, k, p;

   cin >> N;
   reps(i, 1, N){
      cin >> u >> k;
      while(k--){
         cin >> p;
         G[u].pb(p);
      }
   }

   slv();
   return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

using Graph = vector<vector<int>>;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variety
int N;
int d[110];
int f[110];
int ans;
// function
void solve();
void dfs(const Graph &G, int v);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

void solve(){
    cin >> N;
    Graph G(N);
    rep(i, N){
        int hoge; cin >> hoge;
        int k; cin >> k;
        rep(j, k){
            int tmp;
            cin >> tmp;
            tmp--;
            G[i].push_back(tmp);
        }
    }
    rep(i, N) d[i] = -1;
    rep(i, N) f[i] = -1;
    ans = 0;
    for (int i = 0; i < N; i++){
        if (d[i] != -1) continue;
        ans++;
        dfs(G, i);
    }
    rep(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return ;    
}

void dfs(const Graph &G, int v){
    d[v] = ans;
    for(auto next_v : G[v]){
        if (d[next_v] != -1) continue;
        ans++;
        dfs(G, next_v);
    }
    ans++;
    f[v] = ans;
}

C++: #include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

vb seen;
vi k;
vi d;
vi f;

int dfs(const Graph &G, int v, int t) {
    seen[v] = true;
    d[v] = t;
    REP(i, k[v]) {
        int next_v = G[v][i];
        if (seen[next_v]) continue;
        t = dfs(G, next_v, t+1);
    }
    t += 1;
    f[v] = t;
    return t;
}

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

    int n; cin >> n;
    Graph G(n);
    REP(i, n) {
        int u; cin >> u;
        int tmp; cin >> tmp;
        k.push_back(tmp);
        REP(j, tmp) {
            int v; cin >> v;
            G[i].push_back(v-1);
        }
    }

    seen.assign(n, false);
    d.assign(n, 0);
    f.assign(n, 0);

    int t = 0;
    REP(i, n) {
        if (seen[i]) continue;
        t = dfs(G, i, t+1);
    }

    REP(i, n) {
        cout << (i+1) << " " << d[i] << " " << f[i] << "\n";
    }
}