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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 105;
const int INF = 1000;

vector<int> to[MAX_N];
int d[MAX_N], f[MAX_N]; // d：発見時刻、f：完了時刻
int t = 0; int n; 

void init(){
    rep(i,MAX_N){
        d[i] = INF, f[i] = INF;
    }
}

void dfs(int u){
    if(d[u] == INF) d[u] = ++t;
    for(auto v: to[u]){
        if(d[v] == INF) dfs(v); // *もう訪問が完了している頂点には不要に寄らない
    }
    if(f[u] == INF) f[u] = ++t;
}

void dfs_init(){
    rep(i,n){
        if(d[i] == INF) dfs(i);
    }
}

int main()
{
    cin >> n;
    init();
    rep(i,n){
        int u, k; cin >> u >> k; --u;
        rep(_,k){
            int v; cin >> v; --v;
            to[u].push_back(v);
        }
    }
    dfs_init();
    rep(i,n){
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}

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

using namespace std;

vector<int> F;
vector<int> L;
vector<bool> seen;

void dfs(vector<vector<int>> &G,int v,int &t){
    F[v]=t++;

    seen[v]=true;

    for(int i=0;i<G[v].size();i++){
        if(seen[G[v][i]])continue;
        dfs(G,G[v][i],t);
    }

    L[v] = t++; 
}

int main(){

    int n;
    cin >> n;

    vector<vector<int>> G(n);

    for(int i=0;i<n;i++){
        int a,k;
        cin >> a >> k;
        for(int j=0;j<k;j++){
            int b;
            cin >>b;
            G[i].push_back(b-1);
        }
    }

    seen.assign(n,false);
    F.resize(n);
    L.resize(n);
    int t=1;
    
    

    for(int i=0;i<n;i++){
        if(!seen[i])dfs(G,i,t);
        cout << i+1 << " " << F[i] << " " << L[i] << endl;
    }

    return 0;




}

C++: #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int cnt = 1; // time stamp
vector<int> seen, visited;

void dfs(vector<vector<int> > graph, int v) {
    if (seen[v] != 0) return;
    seen[v] = cnt;
    cnt++;
    for (int i = 0; i < graph[v].size(); i++) {
        dfs(graph, graph[v][i]);
    }
    visited[v] = cnt;
    cnt++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n+1);
    for (int i = 1; i <= n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            graph[u].push_back(v);
        }
    }
    seen.assign(n+1, 0);
    visited.assign(n+1, 0);
    for (int i = 1; i <= n; i++) dfs(graph, i);
    for (int i = 1; i <= n; i++) {
        cout << i << " " << seen[i] << " " << visited[i] << endl;
    }
}

C++: #include <iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

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

void dfs_visit(int r) {
  for (int i = 0; i < n; i++) nt[i] = 0;

  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() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

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

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

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

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

  dfs();

  return 0;
}

C++: #include<stdio.h>

void dfs_visit(int);
void dfs();

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

int n,M[N][N];
int color[N],D[N],F[N],t;

int main()
{
  int i,j,u,x,y;

  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++)
    {
      scanf("%d%d",&u,&y);
      u--;
      for(j=0;j<y;j++)
        {
          scanf("%d",&x);
          x--;
          M[u][x]=1;
        }
    }

  dfs();

  return 0;
}

void dfs_visit(int u)
{
  int v;
  color[u]=GRAY;
  D[u]=++t;

  for(v=0;v<n;v++)
    {
      if(M[u][v]==0) continue;
      if(color[v]==WHITE)
        {
          dfs_visit(v);
        }
    }
  color[u]=BLACK;
  F[u]=++t;
}

void dfs()
{
  int u;

  for(u=0;u<n;u++)
    color[u]=WHITE;

  t=0;

  for(u=0;u<n;u++)
    {
    if(color[u]==WHITE)
      dfs_visit(u);
    }

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