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 <iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color [N], d[N], f[N], tt;
int nt[N];

int next(int u) {
  for (int v = nt[u]; v < n; v++) {
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r) {
  for (int i = 0; i < n; i++) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while(!S.empty()) {
    int u = S.top();
    int v = next(u);
    if(v != -1) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  for (int u = 0; u < n; u++) {
    if ( color[u] == WHITE) dfs_visit(u);
  }
  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int main() {
  int u, k, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) M[i][j] = 0;
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include<stdio.h>

void dfs_visit(int);
void dfs();

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],D[N],F[N],t;

int main()
{
  int i,j,u,x,y;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
        M[i][j]=0;
    }

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&y);
      u--;
      for(j=0;j<y;j++)
        {
          scanf("%d",&x);
          x--;
          M[u][x]=1;
        }
    }

  dfs();

  return 0;
}

void dfs_visit(int u)
{
  int v;
  color[u]=GRAY;
  D[u]=++t;

  for(v=0;v<n;v++)
    {
      if(M[u][v]==0) continue;
      if(color[v]==WHITE)
        {
          dfs_visit(v);
        }
    }
  color[u]=BLACK;
  F[u]=++t;
}

void dfs()
{
  int u;

  for(u=0;u<n;u++)
    color[u]=WHITE;

  t=0;

  for(u=0;u<n;u++)
    {
    if(color[u]==WHITE)
      dfs_visit(u);
    }

  for(u=0;u<n;u++)
    printf("%d %d %d\n",u+1,D[u],F[u]);
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

int n;
int M[110][110];
int visited[110];
vector<int> d(110, 0);
vector<int> f(110, 0);
int t;

void dfs(int v){
    
    t++;
    d[v] += t;
    visited[v] = 1;
    
    for (int i = 0; i < n; i++){
        if (M[v][i] == 0) continue;
        
        if(visited[i] == 0) dfs(i);
    }
    
    visited[v] = 2;
    t++;
    f[v] += t;
}

int main(){
    cin >> n;
    t = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) M[i][j] = 0;
        visited[i] = 0;
    }
    
    for (int i = 0; i < n; i++){
        int u;
        cin >> u;
        u--;
        
        int k;
        cin >> k;
        
        for (int j = 0; j < k; j++){
            int v;
            cin >> v;
            v--;
            
            M[u][v]++;
        }
    }
    
    for (int i = 0; i < n; i++){
        if (visited[i] == 0) dfs(i);
    }
    
    for (int i = 0; i < n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    
}

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

vector<vector<int> > list(100);
vector<vector<int> > timed(100);
int times;
void dfs(int now){
	if(!timed[now].empty())	return;
	timed[now].push_back(times++);
	for(int i=0;i<(int)list[now].size();i++){
		dfs(list[now][i]);
	}
	timed[now].push_back(times++);
}

int main(){
	int n;	cin>>n;
	int id,num,ne;
	for(int i=0;i<n;i++){
		cin>>id>>num;
		id--;
		for(int j=0;j<num;j++){
			cin>>ne;
			list[id].push_back(ne-1);
		}
	}
	times=1;
	for(int i=0;i<n;i++){
		if(timed[i].empty())	dfs(i);
	}
	for(int i=0;i<n;i++){
		cout<<i+1;
		for(int j=0;j<(int)timed[i].size();j++){
			cout<<" "<<timed[i][j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
int n;
int m[N][N];
int used[N];
int time = 1;
int bb_start[N];
int bb_end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    bb_start[root] = time++;
    stack<int> s;
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            bb_start[v] = time++;
            s.push(v);
        } else{
            bb_end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, bb_start[i], bb_end[i]);
    }
    return 0;
}

C++: #include <stdio.h>
#define MAX 101

int n, ni = 1;
int A[MAX][MAX] = {0}, a[MAX] = {0}, b[MAX] = {0};

void serch(int x){
  int i;
  
  a[x] = ni++;
  for(i=1; i<=n; i++){
    if(a[i] == 0 && A[x][i] == 1)
      serch(i);
  }
  b[x] = ni++;
}

int main(){
  int i, j, k, x, y;
  
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d%d", &x, &k);
    for(j=1; j<=k; j++){
      scanf("%d", &y);
      A[x][y] = 1;
    }
  }
 
  for(i=1; i<=n; i++){
    if(a[i] == 0)
      serch(i);
  }
  
  for(i=1; i<=n; i++){
    printf("%d %d %d\n", i, a[i], b[i]);
  }
 
  return 0;
}