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<iostream>
#include<vector>

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
public:
 Node()
       : timestampStart(0),
         timestampFinish(0){

  cin >> nodeId;
  unsigned long adjectNodeNum = 0;
  cin >> adjectNodeNum;

  adjectNode.assign(adjectNodeNum, 0);
 
  for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodeNum; ++adjectNode_i){
   cin >> adjectNode[adjectNode_i];
  }

 };

 bool isStampStart(){
  if(timestampStart == 0) return false;
  return true;
 };

 void stampStart(const unsigned long time){
  timestampStart = time;
 };

 void stampFinish(const unsigned long time){
  timestampFinish = time;
 };

 unsigned long getAdjectNodeNum(){
  return adjectNode.size();
 };

 unsigned long getAdjectNode(unsigned  long adjectNode_i){
  return adjectNode[adjectNode_i]-1;

 };

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };

protected:

};

class Graph{
private:
 vector<Node*> graph;

 void DepthFirstSearch(Node* node, unsigned long &time){
  ++time;
  node->stampStart(time);
  for(unsigned long adjectNode_i = 0, adjectNodeMax = node->getAdjectNodeNum(); adjectNode_i < adjectNodeMax; ++adjectNode_i){
   unsigned long nextNode = node->getAdjectNode(adjectNode_i);
   if(!graph[nextNode]->isStampStart()) DepthFirstSearch(graph[nextNode], time);

  }
  ++time;
  node->stampFinish(time);

 };
public:
 Graph(unsigned long nodeNum = 0)
       : graph(vector<Node*>(nodeNum, 0)){

   for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
    graph[node_i] = new Node();
   }

  };

 void DepthFirstSearch(){
  unsigned long time = 0;
  for(unsigned long node_i = 0, nodeMax = graph.size(); node_i < nodeMax; ++node_i){
   if(!graph[node_i]->isStampStart()) DepthFirstSearch(graph[node_i], time);
  }
  
 };

 void display(){
  for(unsigned long node_i = 0, numMax = graph.size(); node_i < numMax; ++node_i){
   graph[node_i]->display();
  }
 };
protected:

};


int main(){

 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int visitTime = 1;
int d[101]={},f[101]={},n[101],v[101][101],id;


void dfs(int cur) { // cur????¨????
	d[cur] = visitTime;// cur????¨??????????????¨????
	visitTime += 1;
	rep(i,n[cur]){ // ??¨????????? v[cur][i] ????????????
		if(d[v[cur][i]]==0){ // v[cur][i] ???????¨??????????
			dfs(v[cur][i]);
		}
	}
	f[cur] = visitTime;// cur ????¨????????????????????¨????
	visitTime += 1;
	// ??¢??°??????????????§???????????? (?????¢??°)
}

int main(void){
	int N;
	cin>>N;
	rep(i,N){
		cin>>id;
		cin>>n[id];
		rep(j,n[id])cin>>v[id][j];
	}
	reg(i,1,N){
		if(d[i]==0){
			dfs(i);
		}
	}
	reg(i,1,N)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

bool adj[105][105] = {0};
int in[105];
int out[105];

int cnt = 1;

void dfs(int now){
    in[now] = cnt++;
    for(int i = 1; i<=100; i++){
        if(adj[now][i] && !in[i])
            dfs(i);
    }
    out[now] = cnt++;    
}


int main(){

    int n = 0;
    scanf("%d", &n);

    for(int i = 1; i<=n; i++){
        int v, c;
        scanf("%d %d", &v, &c);

        while(c--){
            int w = 0;
            scanf("%d", &w);
            adj[v][w] = true;
        }
    }
    
    dfs(1);
    
    for(int i = 1; i<=n; i++){
        printf("%d %d %d\n", i, in[i], out[i]);
    }

    //system("PAUSE");
    return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;

int n,u,k,v;
int g[102][102];
int d[102],f[102];
int sn[102];
int cnt=1;

void dfs(int x);

int main(){
  memset(d,0,sizeof(d));
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>u>>k;
    sn[i]=0;
    for(int j=1;j<=k;j++){
      cin>>v;
      g[u][v]=1;
    }
  }
  
  dfs(1);

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

  return(0);
}

void dfs(int x){
  
  sn[x]=1;
  d[x]=cnt;
  cnt++;
  
  for(int i=1;i<=n;i++){
    if(g[x][i]==1 && sn[i]==0){
      dfs(i);
    }
  }

  f[x]=cnt;
  cnt++;

}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 103;
int G[MAX][MAX];
int color[MAX];
int nt[MAX], d[MAX], f[MAX];
int tt, n;

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

void dfs_visit(int r) {
  memset(nt, 0, sizeof(nt));
  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) {
      if (color[v] == WHITE) {
	color[v] = GRAY;
	d[v] = ++tt;
	S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  memset(color, WHITE, sizeof(color));
  memset(nt, 0, sizeof(nt));
  tt = 0;

  rep(u,n) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  rep(i,n) {
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

int main() {

  cin >> n;
  rep(i,n) memset(G[i], WHITE, sizeof(G[i])); // init
  int u, k;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      int t;
      cin >> t;
      G[i][t-1] = 1;
    }
  }

  dfs();

  return 0;
}