Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

std::vector<vector<int> > G;
std::vector<int> flag;
std::vector<int> in;
std::vector<int> out;
int N;
int dfs(int u, int count) {
	if (flag[u] == 1) return -1;
	flag[u] = 1;
	
	in[u] = count;
	for (int i = 0; i < N; ++i) {
		if (flag[i] == 0 && G[u][i] == 1) {
			count = dfs(i, count + 1);
		}
	}
	out[u] = count + 1;
	return count + 1;
}

int main(int argc, char const *argv[]) {
	
	cin >> N;

	for (int i = 0; i < N; ++i) {
		G.push_back(vector<int>());
		flag.push_back(0);
		in.push_back(0);
		out.push_back(0);
		for (int j = 0; j < N; ++j) {
			G[i].push_back(0);
		}
	}

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

	int count = 1;
	for(int i = 0; i < N; i++) {
		int r = dfs(i, count);
		if (r != -1) {
			count = r + 1;
		}
	}

	for (int i = 0; i < N; ++i) {
		cout << i + 1 << " " << in[i] << " " << out[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <stack>

using namespace std;

static const int N = 100;
static const int YET = 0;
static const int ALREADY = 1;

int state[N];
int timeTable[N][2];
int timeCount = 0;
int currentV;
stack<int> st;
int M[N][N];

void travel() {
  while(!st.empty()) {
    currentV = st.top();
    st.pop();

    if(state[currentV] == YET) {
      timeCount++;
      timeTable[currentV][0] = timeCount;
      state[currentV] = ALREADY;
      st.push(currentV);

      for(int i = N; i > -1; i--) {
        if(M[currentV][i] == 1 && state[i] == YET) {
          st.push(i);
        }
      }
    }
    else if(timeTable[currentV][1] == 0){
      timeCount++;
      timeTable[currentV][1] = timeCount;
    }
  }
}
int main(void) {


  int n, u, k, v;

  cin >> n;

  //?????????
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

  //Graph -> Matrix
  for(int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;//0-origian
    for(int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    } 
  }

  st.push(0);
  travel();
  for(int i = 0; i < N; i++) {
    if(state[i] == YET) {
      st.push(i);
      travel();
    }
  }


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

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

static const int MAX_NUM = 100;

void dsf_cal(int matrix[][MAX_NUM + 1], int state[], int time[][2], int index, int num)
{
    static int t = 0;
    stack<int> S;

    S.push(index);
    state[index]   = 1;
    time[index][0] = t;
    ++t;

    while (S.empty() != true) {
        int i;
        int target = S.top();
        for (i = 0; i < num; i++) {
            if (state[i] == 0) {
                S.push(i);
                state[i]   = 1;
                time[i][0] = t;
                ++t;
                break;
            }
        }
        if (i == num) {
            time[target][1] = t;
            ++t;
            S.pop();
        }
    }

    return;
}

void DSF(int matrix[][MAX_NUM + 1], int num)
{
    int state[MAX_NUM]   = {0};
    int time[MAX_NUM][2] = {0};

    for (int i = 0; i < num; i++) {
        if (state[i] == 0) {
            dsf_cal(matrix, state, time, i, num);
        }
    }

    for (int i = 0; i < num; i++) {
        printf("%d %d %d\n", i, time[i][0], time[i][1]);
    }

    return;
}

int main(void)
{
    int num;
    int index, elemNum;
    int matrix[MAX_NUM + 1][MAX_NUM + 1] = {0};

    scanf("%d", &num);
    for (int i = 0; i < num; i++) {
        scanf("%d %d", &index, &elemNum);
        for (int j = 0; j < elemNum; j++) {
            scanf("%d", matrix[i+1][j]);
        }
    }

    DSF(matrix, num);

    return 0;
}