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>
const int MAXN = 105;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int a[MAXN][MAXN];
int color[MAXN];
int d[MAXN];
int f[MAXN];
int n, tt = 0;
using namespace std;

void dfs(int u)
{
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v = 0; v < n; v++)
	{
		if(a[u][v] == 0)
			continue;
		if(color[v] == WHITE)
		{
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

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

int main ()
{
	int k, u, temp;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++)
		{
			cin >> temp;
			temp--;
			a[u][temp] = 1;
		}
	}
	dfs_init();
	return 0;
}

C++: #include<stdio.h>
#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) { //再帰によるDFS
	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++) {
		if (color[u] == WHITE)dfs_visit(u);
	}

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

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

	dfs();

	return 0;
}

C++: /*
** dfs 遍历图
*/

# include <cstdio>
# include <cstring>
# include <stack>
using namespace std;

const int MAX = 100 + 2;

int g[MAX][MAX], d[MAX], f[MAX], c[MAX], n;

void init() {
    memset(g, 0, sizeof(g));
    memset(d, 0, sizeof(d));
    // memset(f, 0, sizeof(f));
    memset(c, 0, sizeof(c));
    scanf("%d", &n);
    int u, v, k;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &u, &k);
        while (k--) {
            scanf("%d", &v);
            g[u][v] = 1;
        }
    }
}

void dfs() {
    stack<int> s;
    s.push(1);
    int t = 1, node;
    d[1] = t;
    c[1] = 1;

    while(!s.empty()) {
        t++;
        node = s.top();
        int p = 1;
        for (; p <= n; p++) {
            if (g[node][p] != 0 && c[p] == 0) {
                s.push(p);
                d[p] = t;
                c[p] = 1;
                break;
            }
        }
        if (p > n) {
            f[node] = t;
            s.pop();
        }
    }
}

void solve() {
    init();
    dfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

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

int n;
int t;
vector<int> G[MAX];
bool used[MAX];
int d[MAX];
int f[MAX];

void DFS(int s) {
	if (used[s]) return;
	used[s] = true;
	d[s] = t++;
	for (int &v : G[s]) {
		DFS(v);
	}
	f[s] = t++;
}

int main()
{
	cin >> n;
	for (int i = 0, u, k; i < n; i++) {
		cin >> u >> k;
		for (int j = 0, v; j < k; j++) {
			cin >> v;
			G[u - 1].push_back(v - 1);
		}
	}
	t = 1;
	bool flag;
	do {
		flag = false;
		for (int i = 0; i < n; i++) {
			if (!used[i]) {
				DFS(i);
				flag = true;
				break;
			}
		}
	} while (flag);
	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

ll t = 0;
vector <vector <bool>> v(100, vector <bool> (100, 0));
vector <ll> color(100);
vector <ll> start(100);
vector <ll> finish(100);

void dfs(ll i) {
  color.at(i) = 1;
  t++;
  start.at(i) = t;
  rep(j, color.size()) {
    if (v.at(i).at(j) == 0) continue;
    if (color.at(j) == 0) dfs(j);
  }
  color.at(i) = 2;
  t++;
  finish.at(i) = t;
  return;
}

int main() {
  ll n;
  cin >> n;
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b;
    rep(j, b) {
      cin >> c;
      if (a != c) {
        v.at(a-1).at(c-1) = 1;
      }
    }
  }
  rep(i, n) color.at(i) = 0;
  rep(i, n) {
    if (color.at(i) == 0) dfs(i);
  }
  rep(i, n) cout << i+1 << ' ' << start.at(i) << ' ' << finish.at(i) << endl;
}