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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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<iostream>
#include<vector>
#define SIZE 1000000
using namespace std;

struct Stack{
  int line[SIZE];
  int top;
  void init(){
    top = 0;
  }
  bool empty(){
    return top==0;
  }
  void push(int x){
    line[top]=x;
    top ++;
  }
  int pop(){
    if(empty()) return -1;
    top--;
    return line[top];
  }
};
struct Node
{
  vector<int> toList;
  int dt;
  int ft;
};

Stack stack; 
int t; //time

void init(vector<Node>& nodes)
{
  t=0;
  stack.init();
  stack.push(0);
  for(int i=0;i<nodes.size();i++){
    nodes[i].ft=-1;
    nodes[i].dt=-1;
  }
}
void print(vector<Node> nodes)
{
  int n=nodes.size();
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<nodes[i].ft<<" "<<nodes[i].dt<<endl;
  }
}
void dfs(vector<Node>& nodes)
{ 
  int idx=stack.pop();
  if(idx<0){
    for(int i=0;i<nodes.size();i++){
      if(nodes[i].ft<0){
	idx=i;
	break;
      }
    }
  }
  //cout<<idx+1<<":";
  if(idx>=0){
    if(nodes[idx].ft<0){
      //cout<<" find";
      t++;
      nodes[idx].ft=t;
    }
    if(nodes[idx].toList.size()<=0 or nodes[idx].toList[0]==idx){
      //cout<<" toList.size==0"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
    int count=0;
    for(int i=0;i<nodes[idx].toList.size();i++){
      if(nodes[nodes[idx].toList[i]].dt<0){
	//cout<<" jumpto "<<i+1<<endl;
	count++;
	stack.push(idx);
	stack.push(nodes[idx].toList[i]);
	dfs(nodes);
      }
    }
    if(count==0 && nodes[idx].dt<0){
      //cout<<" finish"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
  }else{
    //cout<<"finish dfs"<<endl;
  }
}

int main()
{
  int n,u,k;
  cin>>n;
  vector<Node> nodes(n);
  for(int i=0;i<n;i++){
    cin>>u>>k;
    nodes[i].toList.resize(0);
    for(int j=0;j<k;j++){
      int tmp;
      cin>>tmp;
      nodes[i].toList.push_back(tmp-1);
    }
  }
  init(nodes);
  //print(nodes);

  dfs(nodes);
  print(nodes);
  return 0;
}

C++: 


/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

vector<vector<int>> graph(101);

vi d(101, -INF), f(101);

int cur = 0;

void dfs(int s){
  d[s] = ++cur;
  for (auto next : graph[s]) {
    if (d[next] != -INF) continue;
    dfs(next);
  }
  f[s] = ++cur;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  graph.resize(n); d.resize(n); f.resize(n);

  rep(i, n) {
    int u, k; cin >> u >> k;
    --u;
    rep(j, k) {
      int v; cin >> v; --v;
      graph[u].push_back(v);
    }
  }
  dfs(0);

  for (int i = 0; i < n; ++i) {
    if (d[i] == -INF) dfs(i);
    cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
  }

  return 0;
}

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

using namespace std;

const int MAX = 101;

vector<int> G[MAX];
int d[MAX], f[MAX];
int *T;

void dfs(int u) {

    if (!d[u]) d[u] = ++(*T);

    for (int v : G[u]) {
        if (!d[v]) {
            d[v] = ++(*T);
            dfs(v);
        }
    }

    if (!f[u]) f[u] = ++(*T);
}

int main() {

    int n;
    cin >> n;

    int t = 0;
    T = &t;
    fill(d, d + MAX, 0);
    fill(f, f + MAX, 0);

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[u].push_back(v);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (!d[i]) dfs(i);
    }


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

C++: #include <bits/stdc++.h>
using namespace std;
#define N 100
int t = 0;
stack<int> st;
int d[N + 1], f[N + 1], V[N + 1];
int adj[N + 1][N + 1];

void dfs(int i, int n)
{
    for (int j = 0; j < V[i]; j++)
    {
        if (d[adj[i][j]] == -1)
        {
            d[adj[i][j]] = ++t;
            dfs(adj[i][j], n);
        }
    }
    f[i] = ++t;
}

int main()
{
    int n;
    cin >> n;
    V[0] = n;
    for (int i = 0; i < n; i++)
        adj[0][i] = i + 1;
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        V[u] = k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            adj[u][j] = v;
        }
    }

    for (int i = 0; i <= n; i++)
        d[i] = f[i] = -1;

    dfs(0, n);

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