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 <vector>

using namespace std;

#define MAX_N (105)

vector<int> G[MAX_N];
bool arrived[MAX_N];
int d[MAX_N];
int f[MAX_N];
int n;
int t;
void dfs( int cur ) {
    t++;
    d[cur] = t;

    for ( int i = 0; i < G[cur].size(); i++ ) {
	int next = G[cur][i];
	if ( !arrived[next] ) {
	    arrived[next] = true;
	    dfs( next );
	}
    }

    t++;
    f[cur] = t;

    return;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	u--;
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    v--;
	    G[u].push_back(v);
	}
    }

    t = 0;
    dfs(0);

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

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	if (book[u] == white) return; 
	else
		if (book[u] == black)
		{
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
				dfs(*it-1);
			book[u] = white;
			t[u][1] = ++tot;
		}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u,k,v;
		scanf("%d%d", &u,&k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for(int i=0;i<n;i++)
		if(book[i]==black)
	       dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d", i + 1, t[i][0], t[i][1]);
		if (i != n - 1)printf("\n");
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
static const int N = 100;

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

void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] == 1 && color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_print() {
	for (int i = 0; i < n; i++) color[i] = WHITE;
	tt = 0;
	for (int i = 0; i < n; i++) {
		if (color[i] == WHITE) {
			dfs_visit(i);
		}
	}

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

int main() {
	cin >> n;
	int u, k;
	int index;

	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;
		for (int j = 0; j < k; j++) {
			cin >> index;
			M[u - 1][index - 1] = 1;
		}
	}
	dfs_print();
}

C++: #include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

#define NMAX 100
#define NIL -1

int d[NMAX + 1];           // start time, 1-origin
int f[NMAX + 1];           // finish time, 1-origin
stack<int> S;              // visited but not finished
vector<int> adj[NMAX + 1]; // adj
int n = 0;
int cnt = 0;

int next_unvisited_adj(int u) { // next not visited adj of u
    for (vector<int>::iterator it = adj[u].begin(); it != adj[u].end(); it++) {
        if (d[*it] == 0) // not finished
            return *it;
    }
    return NIL;
}

int next_unvisited() {
    for (int i = 1; i <= n; i++) {
        if (d[i] == 0)
            return i;
    }
    return NIL;
}

void dfs() {
    int x; // start vertex
    while ((x = next_unvisited()) != NIL) {
        // printf("dfs component of %d\n", x);
        S.push(x);
        d[x] = ++cnt;
        while (!S.empty()) { // dfs this component
            // check if the last visited guy is finished
            // if yes, pop it from the stack
            // if no, push the next unfinished adj of it
            int u = S.top();
            // printf("u=%d\n", u);
            int v = next_unvisited_adj(u);
            if (v != NIL) {
                if (d[v] == 0) { // v is not visited
                    // printf("%d is found\n", v);
                    d[v] = ++cnt;
                    S.push(v);
                }
            } else { // u is finished
                // printf("%d is finished\n", u);
                S.pop();
                f[u] = ++cnt;
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        d[i] = 0; // not visited
        f[i] = 0; // not finished
    }
    for (int i = 0; i < n; i++) {
        int u, k, v;
        scanf("%d", &u);
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            adj[u].push_back(v);
        }
    }
    dfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}