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 <bits/stdc++.h>
using namespace std;

const int MAX=200;

int state[MAX],d[MAX],f[MAX],N;
vector<int> T[MAX];
stack<int> S;

void DFS(){
    int time=0,count=0;
    while(count!=N){
        for(int j=0;j<N;j++){
            if(state[j]==0){
                S.push(j);
                state[j]=1;
                time++;
                d[j]=time;
                break;
            }
        }
    while(S.size()){
        int a=S.top();
        bool flag=true;
        for(int i=0;i<T[a].size();i++){
            if(state[T[a][i]]==0){
                S.push(T[a][i]);
                state[T[a][i]]=1;
                time++;
                d[T[a][i]]=time;
                flag=false;
                break;
            }
        }
            if(flag){
                time++;
                state[a]=2;
                count++;
                f[a]=time;
                S.pop();
            }
            
        }
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
   
    int u,k,a;cin>>N;
    
    for(int i=0;i<N;i++){
        state[i]=0;
        d[i]=0;
        f[i]=0;
    }
    
    for(int i=0;i<N;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>a;
            a--;
            T[u].push_back(a);
        }
    }
    DFS();
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<stack>
#define MAX 105
#define WT 0
#define GR 1
#define BK 2

using namespace std;

int M[MAX][MAX];
int cr[MAX], d[MAX], f[MAX];
int t;
stack<int> ck;
void dfs_init(int n)
{
    t = 1;

    for(int i = 1; i <= n; i++)
        cr[i] = WT;

    return;
}
void dfs(int k,int n)
{
    if(cr[k] == WT)
    {
        cr[k] = GR;
        d[k] = t;
        t++;
        ck.push(k);

        for(int i = 1; i <= n; i++)
        {
            if(M[k][i] == 1 && cr[i] == WT)
                dfs(i,n);
            else if(i == n)
            {
                dfs(ck.top(),n);ck.pop();
            }
        }
    }
    else if(cr[k] == GR)
    {
        ck.pop();
        cr[k] = BK;
        f[k] = t;
        t++;

        if(!ck.empty())
            dfs(ck.top(),n);
        else
            return;
    }
}
int main()
{
    int i, j, n, p, q, tmp;

//Set the matrix: M[n][n]
    for(i = 0; i < MAX; i++)
        for(j = 0; j < MAX; j++)
            M[i][j] = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
    {
        scanf("%d%d", &p, &q);

        for(j = 0; j < q; j++)
        {
            scanf("%d", &tmp);
            M[p][tmp] = 1;
        }
    }

    //DFS:d[v] and f[v] for start and end
    dfs_init(n);
    dfs(1,n);

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
vector<bool>seen(1000,false);
vector<pair<int,int>>ans(1000);
vector<int>first_order(1000,10e7),last_order(1000,10e7);
void dfs(const vvll &gura, int v, int& now) {
    first_order[v] = min(first_order[v],now++);

    seen[v] = true; 
    for (auto next_v : gura[v]) { 
        if (seen[next_v]) continue;
        dfs(gura, next_v, now);
    }

    last_order[v] = min(last_order[v],now++);
}
int main(){
    int n;
    cin >> n;
    vvll gura(n);
    for(int i=0;i<n;i++){
        int ww; cin >>ww;
        int w;
        cin >> w;
        for(int j=0;j<w;j++){
            int d;
            cin >> d;
            gura.at(i).push_back(d-1);
        }
    }
    int now = 1;
    for(int i=0;i<n;i++){
        if(seen[i])continue;
    dfs(gura,i,now);
    }
    for(int i=0;i<n;i++){
        cout << i+1<<" "<< first_order[i]<<" "<<last_order[i]<<endl;
    }
}

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

using namespace std;

int n, d[110], f[110], t = 0;
set<int> st;
vector<int> g[110];

void dfs(int m) {
  t++;
  d[m] = t;
  st.erase(m);
  for(int i = 0; i < g[m].size(); i++) {
    if(d[g[m][i]] == -1) {
      dfs(g[m][i]);
    }
  }
  t++;
  f[m] = t;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    int index, k, v;
    cin >> index >> k;
    for(int j = 0; j < k; j++) {
      cin >> v;
      g[index].push_back(v);
    }
    st.insert(index);
    d[index] = -1;
  }
  while(!st.empty()) {
    auto itr = st.begin();
    dfs(*itr);
  }
  for(int i = 0; i < n; i++)
    cout << i+1 << " " << d[i+1] << " " << f[i+1] << endl;

  return 0;
}