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<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define c cout<<"#"<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
//?????????????????????????????????
SI s;//?¨?????????????????????????
int n;//??????????????°
int t;//??????
int d[101];//??????????????????????¨????????????????????????????????????????
int f[102];//??????????????£??\?????????????????????????????????????????????????????????
int a[101][101];//??£??\?????????
int p[101];//??£??\?????????????¨???????????????????????????????
int flag;//???
int main()
{
	cin>>n;
	FOR(i,1,n+1)//??£??\??????????????????
	{
		int k,m;cin>>k>>m;
		a[k][0]=m;
		FOR(j,1,m+1)
		{
			int x;cin>>x;
			a[k][j]=x;
		}
	}
	d[1]=1;int o=1;
	FOR(i,1,101)p[i]=1;//??£??\??????????????????????????????????????????1???????????????
	for(s.push(o),t=2;;t++)
	{
		//s.top()?????????????????????????????????
		if(a[s.top()][0]==0)
		{
			f[s.top()]=t;
			s.pop();
		}
		else
		{
			int next=a[s.top()][p[s.top()]];//next????¬?????¨?????????????????????????
			for(;d[next]!=0;)//???????????????????¨??????????????????¢???
			{
				p[s.top()]++;//????????????????????????????¬??????????????????????
				if(p[s.top()]>a[s.top()][0])//?????????????????£????????????????????????????¨??????????????????°
				{
					f[s.top()]=t;
					s.pop();//?¬?????¨????????????????????????????
					flag=1;//???????????????
					break;//????????????????????????
				}
				next=a[s.top()][p[s.top()]];//?¨????????????????????????´??°
			}
			if(flag==0)//?????????????????£???????????????????¨??????????????????°
			{
				s.push(next);//?¬?????¨??????????for???????????§??????????????????
				d[s.top()]=t;//???????????????????????????????????????????¨????????????????????????????????????????
			}
		}
		flag=0;//???????????????
		if(f[o]!=0)
		{
			int i;
			for(i=o;f[i]!=0;i++);
			if(i>n)break;
			o=i;t++;
			s.push(o);
			d[o]=t;
		}
	}
	FOR(i,1,n+1)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

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

const int MAX_N = 100;
int to[MAX_N][MAX_N];
int ans[MAX_N][2];
bool visited[MAX_N];
int n = 1;

void dfs(int x) {
  if (visited[x]) return;
  visited[x] = true;

  ans[x][0] = n++;
  for (int i=0; to[x][i] != -1; i++) {
    dfs(to[x][i]);
  }
  ans[x][1] = n++;
}

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      to[i][j] = -1;
    }
    ans[i][0] = ans[i][1] = -1;
    visited[i] = false;
  }
  for (int i=0; i<N; i++) {
    int tmp, n;
    cin >> tmp >> n;
    for (int j=0; j<n; j++) {
      int t;
      cin >> t; t--;
      to[i][j] = t;
    }
  }

  for (int i=0; i<N; i++) {
    if (!visited[i]) dfs(i);
  }
  for (int i=0; i<N; i++) {
    cout << i+1 << " " << ans[i][0] << " " << ans[i][1] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 100 + 4;
int cnt, n;
int M[MAXN][MAXN];
int d[MAXN], f[MAXN], status[MAXN];

void dfs( int u )
{
    status[u] = 1;
    d[u] = ++cnt;
    for ( int i = 1; i <= n; i++ ) {
        if ( M[u][i] == 0 ) continue;
        if ( status[i] == 0 ) dfs(i);
    }
    status[u] = -1;
    f[u] = ++cnt;
}

int main()
{
    int u, k, m;
    cnt = 0;
    memset ( M, 0, sizeof(M) );
    memset ( d, 0, sizeof(d) );
    memset ( f, 0, sizeof(f) );
    memset ( status, 0, sizeof(status) );
    cin>>n;
    for ( int i = 0; i < n; i++ ) {
        cin>>u>>k;
        for ( int j = 0; j < k; j++ ) {
            cin>>m;
            M[u][m] = 1;
        }
    }

    for ( int u = 1; u <= n; u++ ) {
        if ( status[u] == 0 ) dfs(u);
    }

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