Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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;
}