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

using namespace std;

vector<int> G[100];
int n;
int t;
int vn,un;
int s[100],f[100];
int inf = 1<<21;
int tim=1;

void dfs(int u){
    //cout << u << " " << s[u] << " " << f[u] << endl;
    s[u] = tim;
    tim++;
    for(int i=0;i<G[u].size();i++){
        int v = G[u][i];
        if(s[v] == inf){
            dfs(v);
        }
    }
    f[u] = tim;
    tim++;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> vn >> un;
        vn--;
        for(int j=0;j<un;j++){
            cin >> t;
            t--;
            //cout << t << " " << vn << endl;
            G[vn].push_back(t);
        }
    }
    fill(s,s+n,inf);
    fill(f,f+n,inf);
    //cout << s[2] << " " << f[3] << endl;
    for(int i=0;i<n;i++){
        if(f[i] == inf) dfs(i);
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << s[i] << " " << f[i] << endl;
    }
    return 0;

}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

enum State {
    unseen, // 未訪問
    seen,   // 発見済み
    end     // 探索終了
};

vector<vector<int>> adj; // 隣接行列
int t = 0; // 時刻
int d[110];   // 頂点vを最初に発見した発見時刻　
int f[110];   // 頂点vの隣接リストを調べ終えた完了時刻
State s[110];

void dfs(int u) {
    ++t;
    d[u] = t;
    s[u] = State::seen;
    // uの隣接点を探索
    for (auto &v: adj[u]) {
        if (s[v] == State::unseen) {
            dfs(v);
        }
    }
    // uは探索済み
    s[u] = State::end;
    ++t;
    f[u] = t;
}

int main() {
    int n; cin >> n;
    adj.resize(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        --u;
        rep(j, k) {
            int v; cin >> v;
            --v;
            adj[i].emplace_back(v);
        }
    }

    // 初期化
    rep(i, n) {
        d[i] = INT_INF;
        f[i] = 0;
        s[i] = State::unseen;
    }

    // DFS
    rep(i, n) {
        if (s[i] == State::unseen) {
            dfs(i);
        }
    }

    // 出力
    rep(i, n) {
        cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

C++: #include <iostream>

using namespace std;

typedef pair<int, int> p;

int n,u,k,t;
int** v;
p* T;

void bfs(int pos) {
  // if visited
  if (T[pos].first) {
    return;
  }
  // check visit
  T[pos].first = ++t;

  int leng = v[pos][0];
  for (int i = 1; i <= leng; i++) {
    bfs(v[pos][i]);
  }
  T[pos].second = ++t;
}

int main() {
  cin >> n;

  v = new int*[n+1];
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    v[u] = new int[k+1];
    v[u][0] = k;
    for (int j = 1; j <= k; j++) {
       cin >> v[u][j];
    }
  }

  T = new p[n+1];
  for (int i = 1; i <= n; i++) {
    T[i] = p(0, 0);
  }

  t = 0;
  bfs(1);

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 100;
int d[MAXN], f[MAXN], tt;
int n,color[MAXN], mat[MAXN][MAXN];
//0表示未访问，1表示正在访问，2表示访问完毕
void dfs_visit(int node)
{
	int i;
	color[node] = 1;
	d[node] = ++tt;  //记录最初的访问时间
	for (i = 0; i < n; i++)
	{
		if (mat[node][i] == 0)	continue;
		if (color[i] == 0)	dfs_visit(i);
	} 
	color[i] = 2;  
	f[node] = ++tt;  //访问结束
}

void dfs()
{
	int i;
	for (i = 0; i < n; i++)	color[i] = 0;  //初始化为未访问状态
	tt = 0; //从0开始计时
	for (i = 0; i < n; i++)
	{
		if (color[i] == 0)
			dfs_visit(i);
	}
	for (i = 0; i < n; i++)	printf("%d %d %d\n", i + 1, d[i], f[i]);
}



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

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

using namespace std;

int solve(vector<vector<int> >& V, vector<int>& d, vector<int>& f, int cur, int timestamp) {
  bool change = false;
  for (int i = 0; i < V[cur].size(); ++i) {
    int next = V[cur][i] - 1;
    if (d[next] == 0) {
      ++timestamp;
      d[next] = timestamp;
      timestamp = solve(V, d, f, next, timestamp);
    }
  }
  ++timestamp;
  if (f[cur] == 0)
      f[cur] = timestamp;
  return timestamp;
}

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

  vector<vector<int> > V(n);
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    vector<int> tmp(k);
    for (int j = 0; j < k; ++j)
      cin >> tmp[j];
    V[u - 1] = tmp;
  }

  vector<int> d(n);
  vector<int> f(n);
  int timestamp = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] == 0) {
      ++timestamp;
      d[i] = timestamp;
      timestamp = solve(V, d, f, i, timestamp);
    }
  }

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

  return 0;
}