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

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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<stdio.h>
#define N 100
#define Black 2
#define White 0
#define Gray 1

int n,A[N][N];
int IRO[N],a[N],b[N],tt ;

void DFS_HOUMON(int u)
{
  int i;
  IRO[u] = Gray;
  a[u] = ++tt;
  for(i=0;i<n;i++)
    {
      if(A[u][i] == 0) continue;
      if(IRO[i] == White)
	{
	  DFS_HOUMON(i);
	}
    }
  IRO[u] = Black;
  b[u] = ++tt;
}

void DFS()
{
  int u;
  for(u=0;u<n;u++)IRO[u] = White;
  tt = 0;

  for(u=0;u<n;u++)
    {
      if(IRO[u] == White)DFS_HOUMON(u);
    }

  for(u=0;u<n;u++)
    {
      printf("%d %d %d\n",u+1,a[u],b[u]);
    }
}
   

int main()
{
  int u,p,q,ii,j;

  scanf("%d",&n);

  for(ii=0;ii<n;ii++)
    {
      for(j=0;j<n;j++) A[ii][j] = 0;
    }
  for(ii=0;ii<n;ii++)
    {
      scanf("%d %d" ,&u,&q);
      u--;
      for(j=0;j<q;j++)
	{
	  scanf("%d",&p);
	  p--;
	  A[u][p] = 1;
	}
    }

  DFS();

  return 0;
}

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

struct StSeq
{
  int m_nBgn;
  int m_nEnd;

  StSeq() : m_nBgn(0), m_nEnd(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StSeq>& rvoDFSrch)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvvnAdjcy.resize(nMaxSiz + 1, vector<int>(nMaxSiz + 1, 0));
  for (int i = 0; i < nMaxSiz; ++i)
  {
    int nx, nSecSiz;
    cin >> nx >> nSecSiz;
    for (int j = 0; j < nSecSiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StSeq oSeq;
  rvoDFSrch.resize(nMaxSiz + 1, oSeq);
}

void fnDepthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, vector<StSeq>& rvoDFSrch, int nx)
{
  static int stnCnt = 0;

  if (rvoDFSrch[nx].m_nBgn)  return;
  rvoDFSrch[nx].m_nBgn = ++stnCnt;

  for (int ny = 1; ny < cnrvvnAdjcy.size(); ++ny)
    if (cnrvvnAdjcy[nx][ny] == 1  &&
        nx != ny                )
      fnDepthFirstSearch(cnrvvnAdjcy, rvoDFSrch, ny);

  rvoDFSrch[nx].m_nEnd = ++stnCnt;
}

void fnResult(const vector<StSeq>& cnrvoDFSrch)
{
  for (int i = 1; i < cnrvoDFSrch.size(); ++i)
    cout << i <<  " " << cnrvoDFSrch[i].m_nBgn << " " << cnrvoDFSrch[i].m_nEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  vector<StSeq> voDFSrch;

  fnInput(vvnAdjcy, voDFSrch);
  for (int nx = 1; nx < voDFSrch.size(); ++nx)
    fnDepthFirstSearch(vvnAdjcy, voDFSrch, nx);
  fnResult(voDFSrch);

  return 0;
}

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

void dfs(int cur);

int A[100][100], d[100], f[100];;
int n,t=0;

int main()
{
    	cin>>n;
        
    	for(int i=0;i<n;++i){

		d[i]=0;
		f[i]=0;

        	for(int j=0;j<n;++j){
            		A[i][j]=0;
        	}
        
        	int m,k; //k=number of adj
        	cin>>m>>k;
        	assert(m==i+1);
        
        	for(int j=0;j<k;++j){
            		int adj;
            		cin>>adj;
            		if(adj){
                		A[i][adj-1]=1;
            		}
        	}
    	}

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

	dfs(0);

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

    	return 0;
}

void dfs(int cur)
{
	t+=1;
	d[cur]=t;

	cerr<<"visiting "<<cur+1<<" "<<t<<endl;

	for(int dst=0;dst<n;++dst){
		if(A[cur][dst]==1&&d[dst]==0){
			dfs(dst);
		}
	}

	t+=1;
	f[cur]=t;

	cerr<<"leaving "<<cur+1<<" "<<t<<endl;

	return;
}

C++: #include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

class Edge {
public:
  int src, dst, cost;
  Edge(int s, int d, int c)
    : src(s), dst(d), cost(c) {}
  friend bool operator<(const Edge& x, const Edge& y) {
    return x.cost < y.cost;
  }
};

typedef Edge State;

class Graph {
public:
  int N;
  vector<Edge>* V;
  int* visited;
  int* from;
  int time;
  int* time_d;
  int* time_f;

  Graph(int n)
    : N(n), time(0) {
    V = new vector<Edge>[N];
    from = new int[N];
    time_d = new int[N];
    time_f = new int[N];
    visited = new int[N];
  }
  ~Graph() {
    delete[] V;
    delete[] from;
    delete[] time_d;
    delete[] time_f;
    delete[] visited;
  }

  void add_edge(int src, int dst, int cost = 1) {
    V[src].push_back(Edge(src, dst, cost));
  }

  void dfs(int start) {
    fill(visited, visited+N, 0);
    stack<State> S;
    S.push(State(-1, start, 0));
    while (!S.empty()) {
      State s = S.top();
      S.pop();
      if (visited[s.dst] == 0) {
        visited[s.dst] = 1;
        time_d[s.dst] = time++;
        from[s.dst] = s.src;
        S.push(s);
        for (auto x : V[s.dst]) {
          if (visited[x.dst] == 0) {
            S.push(State(s.dst, x.dst, s.cost + x.cost));
          }
        }
      } else if (visited[s.dst] == 1) {
        visited[s.dst] = 2;
        time_f[s.dst] = time++;
      }
    }
  }
};

int main () {
  int n;
  cin >> n;
  Graph graph(n);
  for (auto i = 0; i < graph.N; ++i) {
    int u, k;
    cin >> u >> k;
    --u;
    for (auto j = 0; j < k; ++j) {
      int v;
      cin >> v;
      --v;
      graph.add_edge(u, v);
    }
  }
  for (auto i = 0; i < graph.N; ++i) {
    sort(graph.V[i].begin(), graph.V[i].end());
    reverse(graph.V[i].begin(), graph.V[i].end());
  }
  while (true) {
    bool used = false;
    for (auto i = 0; i < graph.N; ++i) {
      if (graph.visited[i] == 0) {
        graph.dfs(i);
        used = true;
        break;
      }
    }
    if (!used) break;
  }
  for (auto i = 0; i < graph.N; ++i) {
    cout << i+1
         << " " << graph.time_d[i]+1
         << " " << graph.time_f[i]+1 << endl;
  }
}