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>
//#include "stdio.h"

using namespace std;

#define N 100

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int n, M[N][N];
int color[N],d[N],f[N];
int world_time;

int next(int node){
  for(int v=0;v<n;v++){
    if(M[node][v] == 1 && color[v] == WHITE){
      return v;
    } 
  }
  return NIL;
}

void dfs_visit(int i){
  
  world_time = world_time + 1;
  stack<int> S;
  S.push(i);
  color[i] = GRAY;
  d[i] = world_time;

  int present,next_node;
  while( !S.empty() ){
    world_time = world_time + 1;
    present = S.top();
    next_node = next(present);

    if(next_node != NIL){
      S.push(next_node);
      d[next_node] = world_time;
      color[next_node] = GRAY;
    }else{
      color[present] = BLACK;
      S.pop();
      f[present] = world_time;
    }
  }
}

void dfs(){
  world_time = 0;

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

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

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


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

  int u,v,k;
  for(int i=0;i<n;i++){
    cin >> u >> k;

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

  dfs();

  return 0;
}

C++: #include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
int a[105][105];
int tim=0;
int first[105],last[105];
int zhuangtai[105];
int us;
int nex[105];
int findnext(int k)
{
    for(int i=nex[k];i<us;i++)
    {
        nex[k]=i+1;
        if(a[k][i]) return i;
    }
    return -1;
}
void visit(int k)
{
    for(int i=0;i<us;i++)
    {
        nex[i]=0;
    }
    stack<int > s;
    s.push(k);
    first[k]=++tim;
    zhuangtai[k]=1;
    while(!s.empty())
    {
        int n=s.top();
        int ne=findnext(n);
        if(ne!=-1)
        {
            if(zhuangtai[ne]==0){
                zhuangtai[ne]=1;
                first[ne]=++tim;
                s.push(ne);
            }
        }else{
            s.pop();
            zhuangtai[n]=2;
            last[n]=++tim;
        }
    }
}
void dfs()
{
    for(int i=0;i<us;i++)
    {
        zhuangtai[i]=0;
        nex[i]=0;
    }
    for(int i=0;i<us;i++)
    {
        if(zhuangtai[i]==0) visit(i);
    }
    for(int i=0;i<us;i++)
    {
        printf("%d %d %d\n",i+1,first[i],last[i]);
    }
}
int main()
{
    scanf("%d",&us);
    for(int i=0;i<us;i++)
    {
        int p,x;
        scanf("%d%d",&p,&x);
        p--;
        for(int j=0;j<x;j++)
        {
            int y;
            scanf("%d",&y);
            y--;
            a[p][y]=1;
        }
    }
    dfs();
    return 0;
}

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

int G[105][105]={};
int d[105]={},f[105]={};
int N,T=0;

void Gprint(int n){
    cout<<"\\|";
    for(int i=0; i<n; i++)cout<<i+1;
    cout<<endl;
    for(int i=0; i<n+2; i++)cout<<"-";
    cout<<endl;
    for(int i=0; i<n; i++){
        cout<<i+1<<"|";
        for(int j=0; j<n; j++){
            cout<<G[i][j];
        }
        cout<<endl;
    }
}

void dfs(int n){
    if(d[n])return;
    d[n]=++T;
    for(int i=0; i<N; i++){
        if(G[n][i])dfs(i);
    }
    f[n]=++T;
}

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

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

//    Gprint(N);

    for(int i=0; i<N; i++)
        dfs(i);

    for(int i=0; i<N; i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n,t = 0;
int color[100],d[100],f[100],M[100][100];
int nt[100];

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] = ++t;

  while(!S.empty()) {
    int u = S.top();
    int v = next(u);
    if(v != -1) {
      if(color[v] == white) {
        color[v] = gray;
        d[v] = ++t;
        S.push(v);
      }
    }else {
      color[u] = black;
      f[u] = ++t;
      S.pop();
    }
  }

}

void dfs() {
  for(int i = 0;i < n;i++) {
    if(color[i] == white) dfs_visit(i);
  }

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



int main() {


cin >> n;

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

for(int i = 0;i < 100;i++) {
  color[i] = white;
  nt[i] = 0;
  d[i] = 0;
  f[i] = 0;
}

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--;
    M[u][v] = 1;
  }

}

dfs();

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

int G[101][101];
bool visited[101];
int timex[101][2];
int now_time = 1;
int n;

void dfs(int node) {

	if (!visited[node]) {
		visited[node] = 1;
		timex[node][0] = now_time++;
		for (int i = 0; i < n; i++)	{
			if (G[node][i] && visited[i] == 0) {
				dfs(i);
			}
		}
		timex[node][1] = now_time++;
	}
}

void dfs_stack(int node) {

	stack<int> st;
	st.push(node);
	visited[node] = 1;
	timex[node][0] = now_time++;
	while (!st.empty()) {
		int ver = st.top();

		bool flag = false;
		for (int i = 0; i < n; i++)	{
			if (G[ver][i] && visited[i] == 0) {
				visited[i] = 1;
				timex[i][0] = now_time++;
				st.push(i);
				flag = true;
				break;
			}
		}
		if (!flag) {
			timex[ver][1] = now_time++;
			st.pop();
		}
	}

}


int main() {
	
	cin >> n;

	for (int i = 0; i < n; i++)	{
		int id, degree;
		cin >> id >> degree;
		for (int j = 0; j < degree; j++) {
			int idx; cin >> idx;
			G[id - 1][idx - 1] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (!visited[i])
			dfs_stack(i);
	}
	

	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << timex[i][0] << " " << timex[i][1] << endl;
	}


	return 0;
}