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<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;
int color[N],nt[N];
int mp[N][N];
int n,d[N],f[N],tt;
int next(int r){
    
    for(int i=nt[r];i<n;i++){
        nt[r]=i+1;
        if(mp[r][i])return i;
        
    }
    return -1;
    
}

void dfs_visit(int r){
    rep(i,n){nt[i]=0;}
    stack<int> s;
    s.push(r);
    d[r]=++tt;
    color[r]=gray;
    while(!s.empty()){
        int u=s.top();
        int v=next(u);
        if(u!=-1){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
        }else{
            f[u]=++tt;
            color[u]=black;
            s.pop();
        }
        
        
        
    }
    
    
}



void dfs(){
    tt=0;
    rep(i,n){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}


int main(){
    cin>>n;
    rep(i,N){
        rep(i,N){
            mp[i][n]=0;
        }
    }
    rep(i,n){
        int a,b;
        cin>>a>>b;
        a--;
        rep(i,b){
            int c;
            cin>>c;
            c--;
            mp[a][c]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;

std::vector<pair<int, int> > stamp(101);
std::vector<std::vector<int> > v(101);
bool isCheckd[101];
int cnt = 0;

void dfs(int k){
	cnt++;
	isCheckd[k] = true;
	stamp[k].first = cnt;
	for(int i=0;i<v[k].size();i++){
		int next = v[k][i];
		if(!isCheckd[next]){
			dfs(next);
		}
	}
	cnt++;
	stamp[k].second = cnt;
}

int main(){
	int n;

	fill(isCheckd,isCheckd+101,false);
	isCheckd[0] = true;
	cin >> n;

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

	dfs(1);

	for(int i=0;i<n;i++){
		cout << i+1 <<" "<< stamp[i+1].first <<" " <<stamp[i+1].second<< endl;
	}

	return 0;
}

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

using namespace std;
int time = 0;

void dfs(int cur, vector<vector <int> > &list, vector<int> &d, vector<int> &f) {
		d[cur] =time;
		time +=1;
    for(int i = 0; i < list.size();i++){
      vector<int>::iterator it = list[cur].end();
	  vector<int>::iterator hoge = find(list[cur].begin(),list[cur].end(),i);
      if(d[i] == 0 && (hoge != it ) ){
        dfs(i,list,d,f);
      }
    }
    f[cur] = time;
    time +=1;
}

int main() {
  int np;
  int k,t,x;
  cin >> np ;
 
  vector <vector <int> > list(np);
  for(int i = 0;i<np;i++) {
    cin >> k;
    cin >> t;
    for(int j = 0; j < t ;j++) {
      cin >>x;
      list[k-1].push_back(x-1);
    }
  }
  vector <int> d(np,0);
  vector <int> f(np,0);
  dfs(0,list,d,f);
  for(int i = 0;i < np; i++){
    cout << i+1 <<" "<<d[i]+1 <<" "<<f[i]+1<<endl;
  }


  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct status{
    int idx_node;
    vector<int> children;
    int finded = 0;
    int visited = 0;
};

int step = 0;
vector<status> graph;

void dfs(int now_node){
    ++step;
    graph[now_node-1].finded = step;
    for(auto&& next_node:graph[now_node-1].children){
        if(not graph[next_node-1].finded){
            dfs(next_node);
        }
    }
    ++step;
    graph[now_node-1].visited = step;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);

    //stdi
    int nb_nodes; cin >> nb_nodes;
    graph.resize(nb_nodes);
    for(auto& times:graph){
        int idx_node; cin >> idx_node; graph[idx_node-1].idx_node = idx_node;
        int nb_edges; cin >> nb_edges; graph[idx_node-1].children.resize(nb_edges);
        for(auto& a:graph[idx_node-1].children){
            cin >> a;
        }
        sort(graph[idx_node-1].children.begin(),graph[idx_node-1].children.end());
    }
    
    //dfs
    int root = 1;
    dfs(root);
    
    //stdo
    for(auto& a:graph){
        cout<<a.idx_node<<" "
            <<a.finded<<" "
            <<a.visited<<"\n";
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;

int n;
vector<vector<int> > A;
vector<vector<int> > T;
int timer = 0;

void dfs(int cur){
    timer += 1;
    T[cur][0] = timer;

    for(int dst = 0; dst < n; ++dst){
        if(A[cur][dst] == 1 && T[dst][0] == -1){
            dfs(dst);
        }
    }
    timer += 1;
    T[cur][1] = timer;
}

int main(){
    cin >> n;
    A = vector<vector<int> >(n, vector<int>(n, 0));
    T = vector<vector<int> >(n, vector<int>(2, -1));
    for(int i=0; i<n; ++i){
        int k;
        cin >> k;
        k -= 1;
        int u;
        cin >> u;
        for(int j=0; j<u; ++j){
            int v;
            cin >> v;
            v -= 1;
            A[k][v] = 1;
        }
    }
    for(int i=0; i<n; ++i){
        if(T[i][0] == -1){
          dfs(i);
        }
    }
    for(int i=0; i<n; ++i){
        cout << i+1 << " " << T[i][0] << " " << T[i][1] << endl;
    }
}