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
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			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
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	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<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
using namespace std;

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

// ?????°??¢??°???????????±???????????¢?´¢
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++) color[u] = WHITE;
	tt = 0;

	for(u=0; u<n; u++){ // ????¨???????u????§??????¨????????±???????????¢?´¢
		if( color[u]==WHITE ) dfs_visit(u);
	}
	for(u=0; u<n; u++){
		cout << u+1 << d[u] << f[u] << "\n";
	}
}

int main(){
	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<stdio.h>
#define N 100

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

void dfs_visit(int);
void dfs();

static int n, M[N][N], color[N], d[N], f[N], tt;;

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

  scanf("%d", &n);

  for (i = 0; i < n; i++){
    for (j = 0; j < n; j++){
        M[i][j] = 0;
    }
  }
  
  for (i = 0; i < n; i++){
    for (j = 0; j < n; j++){
        M[i][j] = 0;
    }
  }
  
  for (i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for (j = 0; j < k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  tt++;
  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 i, u;
  for (i = 0; i < n; i++){
      color[i] = WHITE;
  }
  tt = 0;
  for (u = 0; u < n; u++){
    if (color[u] == WHITE){
        dfs_visit(u);
    }
  }
  for (i = 0; i < n; i++){
    printf("%d %d %d\n", i+1, d[i], f[i]);
  }
}

C++: #include<stdio.h>
 
#define MAX 100
#define WHITE -1
#define GRAY 0
#define BLACK 1
 
int n,t;
int color[MAX],d[MAX],f[MAX],Adj[MAX][MAX];
 
dfs(){
  int i;
 
  for(i=0;i<n;i++) color[i]=WHITE;
  t=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE) visit(i);
  }
}
 
visit(int r){
  int i;
 
  color[r]=GRAY;
  d[r]=++t;
 
  for(i=0;i<n;i++){
    if(Adj[r][i]==1 && color[i]==WHITE) visit(i);
  }
 
  color[r]=BLACK;
  f[r]=++t;
}
 
int main(){
  int i,u,k,j,v;
 
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){ 
      Adj[i][j]=0;
    }
  }
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u-1][v-1]=1;
    }
  }
 
  dfs();
 
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
 
  return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
#include<unordered_set>
#include<algorithm>

#define N 1000

int n, u, k, v;
int G[N][N];
std::stack<int> S;
std::unordered_set<int> hasVisited;
int count, d[N], f[N];

void visit(int x) {
    hasVisited.insert(x);
    d[x] = count++;
    for(int i = 1; i <= n; i++) {
        if(G[x][i] != 0 && hasVisited.find(i) == hasVisited.end()) {
            visit(i);
        }
    }
    f[x] = count++;
}

int main() {

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            G[i][j] = 0;
        }
    }
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::cin >> u >> k;
        for(int j = 0; j < k; j++) {
            std::cin >> v;
            G[u][v] = 1;
        }
    }

    count = 1;
    for(int i = 0 ; i < N; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for(int i = 1; i <= n; i++) {
        if(hasVisited.find(i) == hasVisited.end())
            visit(i);
    }
    for(int i = 1; i <= n; i++) {
        printf("%i %i %i\n", i, d[i], f[i]);
    }

    return 0;
}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

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

C++: #include <bits/stdc++.h>

int d[128];
int f[128];
bool c[128][128];
int n;
int t;
int checked[128];

void dfs(int i) {
  if( checked[i] ) return;
  checked[i] = true;
  t += 1;
  d[i] = t;
  for(int k = 1; k <= n; ++k) {
    if( c[i][k] ) {
      dfs(k);
    }
  }
  t += 1;
  f[i] = t;
  return;
}

int main(void) {

  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      c[i][j] = false;
    }
  }

  std::cin >> n;

  int u, k, v;
  for(int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for(int j = 0; j < k; ++j) {
      std::cin >> v;
      c[u][v] = true;
    }
  }

  dfs(1);

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