Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int M[N][N] = {0}, color[N] = {0}, d[N], f[N], tt = 0, n;

void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for (v = 0; v < n; v++) {
    if (M[u][v] == 0) continue;
    if (color[v] == WHITE) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

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

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

int main(void) {
  int u, v, k, i, j;

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

  return 0;
}

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