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>
#define MAX 100
#define BLACK 2
#define WHITE 0
#define GRAY 1
using namespace std;

void dfsInit();
void dfs(int);
int next(int);

int n,A[MAX][MAX];
int color[MAX],d[MAX],f[MAX],nt[MAX];
int time1;
int main(){
  int i,j,u,v,k;
  cin >> n;
  for(i = 0; i < n; i++){
    for(j = 0; j< n; j++){
      A[i][j] = 0;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    u = u-1;
    for(j = 0; j < n; j++){
      cin >> v;
      v = v-1;
      A[u][v] = 1;
    }
  }
  dfsInit();
  return 0;
}

void dfsInit(){
  for(int i = 0; i < n; i++){
    color[i] = WHITE;
    nt[i] = 0;
  }
  time1 = 0;
  for(int u = 0; u < n; u++){
    if(color[u] == WHITE){
      dfs(u);
    }
  }
  for(int i = 0; i < n; i++){
    //printf("%d %d %d\n",i+1,d[i],f[i]);
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int next(int u){
  int v;
  for(v = nt[u]; v < n; v++){
    nt[u] = v+1;
    if(0 < A[u][v]){
      return v;
    }
  }
  return -1;
}
void dfs(int u){
  for(int i = 0; i < n; i++){
    nt[i] = 0;
  }
  stack<int> S;
  S.push(u);
  color[u] = GRAY;
  d[u] = ++time1;
  while(!S.empty() ){
    int r = S.top();
    int v = next(u);
    if(v != -1){
      if(color[v] == WHITE){
        color[v] = GRAY;
        d[v] = ++time1;
        S.push(v);
      }
    }
    else{
      S.pop();
      color[r] = BLACK;
      f[r] = ++time1;
    }
  }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int n, d[101], f[101]; vector<int> v[101];
int dfs(int c, int x) {
  if(d[c] > 0) return x;
  d[c] = x++;
  for(int i = 0; i < v[c].size(); ++i) {
    x = dfs(v[c][i], x);
  }
  f[c] = x++;
  return x;
}
int main() {
  scanf("%d", &n);
  for(int i = 0, u, k; i < n; ++i) {
    scanf("%d %d", &u, &k);
    for(int j = 0, vj; j < k; ++j) {
      scanf("%d", &vj);
      v[u].push_back(vj);
    }
  }
  for(int i = 1, s = 1; i <= n; ++i) {
    s = dfs(i, s);
  }
  for(int id = 1; id <= n; ++id) {
    printf("%d %d %d\n", id, d[id], f[id]);
  }
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#define MAX 101
using namespace std;
int n,tim=0;
int A[MAX][MAX]={0};
int color[MAX]={0},d[MAX]={0},f[MAX]={0};
stack<int> Number_of_vertices;
int input(void){
    int start;
    cin >> n;
    for(int i=0;i<n;i++){
        int id,adj;
        cin >> id >> adj;
        if(i==0){
            start = id-1;
            Number_of_vertices.push(id-1);   
        }
        for(int j=0;j<adj;j++){
            int k;
            cin >> k;
            A[id-1][k-1] = 1;
        }
    }
    return start;
}
void depth_first_search(int id){
    tim++;
    if(color[id]!=1){
        color[id] = 1;
        d[id] = tim;
    }
    for(int i=0;i<n;i++){
        if(A[id][i]==1 && color[i]!=1){
            Number_of_vertices.push(i);
            depth_first_search(i); 
        }
    }
    tim++;
    f[Number_of_vertices.top()] = tim;
    Number_of_vertices.pop();
}
void check(void){
    for(int i=0;i<n;i++){
        if(color[i]==0){
            int start = i;
            Number_of_vertices.push(start);
            depth_first_search(start);
        }
    }
}
void print(void){
    for(int i=0;i<n;i++){
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}
int main(void){
    int start;
    start = input();
    depth_first_search(start);
    check();
    print();
    return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

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

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


void dfs_visit(int r){
    
    rep(i,n)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){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;nt[i]=0;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]){
      p=0;
      dfs(i,p);
    }
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-12 18:24:44
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-12 18:48:30
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e2+10;

int d[MAXN],f[MAXN],a[MAXN][MAXN],n,cnt,u,v,t,book[MAXN];

void dfs(int x)
{
	if(!d[x])	d[x] = ++cnt;
	for(int i = 1; i <= n; ++i)
	{
		if(a[x][i] && !book[i])
		{
			book[i] = 1;
			dfs(i);
		}
	}
	f[x] = ++cnt;
	return;
}

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		cin>>u>>t;
		for(int j = 0; j < t; ++j)
		{
			cin>>v;
			a[u][v] = 1;
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i)
	{
		cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
	}
	return 0;
}