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

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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++: // ALDS1_11_B.cpp
// Graph I - Depth First Search

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

struct Vertex
{
    int id;
    vector<int> adjList;
    int d = 0;
    int f = 0;
};

int cnt = 0;

void dfs(vector<Vertex> &V, int n, int i)
{
    if (V[i].d != 0 && V[i].f != 0)
        return;
    int len = V[i].adjList.size();
    V[i].d = ++cnt;

    for (int j = 0; j < len; j++) {
        int next = V[i].adjList[j];
        if (V[next].d == 0) {
            // V[next].d = ++cnt;
            dfs(V, n, next);
            //V[next].f = ++cnt;
        }
    }
    V[i].f = ++cnt;
}

int main()
{
    int n;
    cin >> n;
    vector<Vertex> V(n);
    int id;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> id >> num;
        V[id-1].id = id-1;
        int tmp;
        for (int j = 0; j < num; j++) {
            cin >> tmp;
            V[id-1].adjList.push_back(tmp-1);
        }
    }
    for (int i = 0; i < n; i++)
        dfs(V, n, i);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i + 1, V[i].d, V[i].f);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

int main(){

  int vertex_num, time;
  cin >> vertex_num;
  vector<vector<int>> adjacent_graph;
  adjacent_graph.resize(101);
  int discover[101],finished[101];
  rep(i,101) discover[i] = finished[i] = -1;

  rep(i,vertex_num){
    int vertex, adjacent_num,tmp;
    vector<int> input_graph;
    cin >> vertex >> adjacent_num;
    rep(j,adjacent_num){
      cin >> tmp;
      input_graph.emplace_back(tmp);
    }
    adjacent_graph[vertex] = input_graph;
  }

  stack<int> stk;
  time = 0;
  for(int i=1;i<=vertex_num;i++){
    if(discover[i] == -1){
      stk.emplace(i);
      discover[i] = ++time;
    }
    while(!stk.empty()){
      int now = stk.top();
        bool hasnext = false;
        rep(j,adjacent_graph[now].size()){
          int next = adjacent_graph[now][j];
          if(discover[next] == -1) {
            discover[next] = ++time;
            stk.emplace(next);
            hasnext = true;
            break;
          }
        }
        if(!hasnext){   
        finished[now] = ++time;
        stk.pop();
        }
    }
  }

  for(int i =1;i<=vertex_num; i++){
    cout << i << " " << discover[i] << " " << finished[i] << endl;
  }

  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct Node{
    int id, v;
    bool done = false;
    Node(int id, int v=0): id(id), v(v) {}
    Node(): id(0), v(0) {}

    bool operator==(const Node& x) { return v == x.v; }
    bool operator!=(const Node& x) { return v != x.v; }
    bool operator<(const Node& x) { return v < x.v; }
    bool operator>(const Node& x) { return v > x.v; }
    bool operator<=(const Node& x) { return v <= x.v; }
    bool operator>=(const Node& x) { return v >= x.v; }

    bool comp(Node node){
        return v < node.v;
    }
};

struct Edge{
    int from, to, cost, id;
    Edge(int from, int to, int cost=1, int id=-1): from(from), to(to), cost(cost), id(id) {}

    bool comp(Edge e){
        return cost < e.cost;
    }
};

struct Graph{
    int N;
    vector<vector<Edge>> adj;
    vector<Node> node;

    Graph(int N): N(N) {
        adj.resize(N, vector<Edge>());
        node.resize(N);
        for(int i=0; i<N; ++i) node[i].id = i;
    }

    Graph() {}

    void add_edge(int i, int j, int cost=1, int id=-1){
        Edge e(i, j, cost, id);
        adj[i].emplace_back(e);
    }

    vector<Edge> get_adj(Node node){
        return adj[node.id];
    }

    void assign(int n){
        N = n;
        adj.assign(N, vector<Edge>());
        node.assign(N, Node());
        for(int i=0; i<N; ++i) node[i].id = i;
    }
};

Graph G;
VI d,f;

int dfs(int node, int t){
    G.node[node].done = true;
    d[node] = t;

    for(Edge e : G.adj[node]){
        if(G.node[e.to].done) continue;
        t = dfs(e.to, t+1);
    }

    f[node] = t+1;
    return t+1;
}

int main(void){
    int n; cin >> n;
    d.assign(n,0);
    f.assign(n,0);
    G.assign(n);
    REP(i,n){
        int u,k; cin >> u >> k;
        u--;
        REP(j,k){
            int v; cin >> v;
            v--;
            G.add_edge(u,v);
        }
    }

    int t = 0;
    REP(i,n){
        if(G.node[i].done) continue;
        t = dfs(i,t+1);
    }

    REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << en;
    return 0;
}