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>

#define fp 				pop_front
#define bp 				pop_back
#define all(x) 			x.begin() , x.end()
#define mp 				make_pair
#define pb 				push_back
#define pf 				push_front
#define se 				second
#define f 				first
#define sz 				size()
#define sqr(x) 			((x) * (x))
#define cub(x) 			sqr(x) * (x)
#define ios 			std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define y1 				qazwsxedcrfvtgb
#define LOGMAX          17
#define MX              1 << 22
#define l(n)            n << 1
#define r(n)            (n << 1) + 1
#define FIND(N,pos)     ((N) & (1 << (pos)))
#define sf(h)           scanf("%d",&h)
#define sff(h,b)        scanf("%d%d",&h,&b)
#define sfff(h,b,c)     scanf("%d%d%d",&h,&b,&c)
#define TCASE(test)     for(int z = 1;z <= test;z++)
#define PRINT           printf("Case %d: ",z)
#define en              "\n"
#define lwb             lower_bound
#define upb             upper_bound
#define	pii				pair <int, int>
#define	pil				pair <int, long long>
#define	pli				pair <long long, int>
#define	pll				pair <long long, long long>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = int(1.5 * 1e7);
const int inf = 1e9 + 7;
const ll ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;

int n, x, y, k1, t, a[101][101], st[101], ft[101], was[101];
vector <int> v[101];

void dfs(int k){
	st[k] = ++t;
	was[k] = 1;
	for(int i = 0; i < v[k].sz; ++i){
		int to = v[k][i];
		if(!was[to]){
			dfs(to);
		}
	}
	ft[k] = ++t;
}

main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x >> k1;
		for(int j = 0; j < k1; ++j){
			cin >> y;
			v[x].pb(y);
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i){
		cout << i << " " << st[i] << " " << ft[i] << en;
	}
}

C++: 
#include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    for (int j = 1; j <= n; ++j) {
        if (G[i][j] != 1 || STATE[j] != NOT_VISIT) continue;
        dfs(j);
    }
    STATE[i] = FOUND;
    f[i] = ++tt;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x;
  
  memset(find_t,255,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    flag[id]=0;
    for(int l=0;l<cnt;l++){
      cin>>x;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }
  
  for(int i=1;i<=n;i++){
    if(flag[i]==0)
      DFS(i);
  }
  Print();
  
  return 0;
}

  void DFS(int p){
    if(flag[p]==0){
      find_t[p]=t++;
      flag[p]=1;
    }
    else
      return;
    
    if(lft[p]!=-1)
      DFS(lft[p]);
    if(rht[p]!=-1)
      DFS(rht[p]);

    end_t[p]=t++;
  }

  void Print(){
    for(int i=1;i<=100;i++){
      if(find_t[i]!=-1)
	printf("%d %d %d\n",i,find_t[i],end_t[i]);
    }
  }

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

using namespace std;

const int WHITE=0, GRAY=1, BLACK=2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> discover;
    vector<int> finish;
    vector<int> state;
    int time = 1;
    
    DFS(int n):n(n) {
        g.assign(n, vector<int>());
        discover.assign(n, -1);
        finish.assign(n, -1);
        state.assign(n, WHITE);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (state[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        state[u] = GRAY;
        discover[u] = time++;
        for (int v : g[u]) {
            if (state[v] == WHITE) {
                dfs(v);
            } 
        }
        finish[u] = time++;
        state[u] = BLACK;
    }
    
    void print() {
        for (int i = 0; i < n; i++) {
            cout << i << ":";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    DFS dfs(n);
    for (int i = 0; i < n; i++) {
       int u, k;
       cin >> u >> k;
       u--;
       for (int j = 0; j < k; j++) {
           int v;
           cin >> v;
           v--;
           dfs.addEdge(u, v);
       }
    }
    
    //dfs.print();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) <<  " " << dfs.discover[i] << " " << dfs.finish[i] << endl; 
    }
    
    return 0;
}