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<stdio.h>
#include<stack>
using namespace std;
int begins[100] = {0},ends[100] , a[100][100],f[100]={0};
stack<int> tc;
int cnt = 0;
int n;
void inset(int u){
    int i;
    if(begins[u] != 0)return;
    begins[u] = ++cnt;
    tc.push(u);
 for(i = 1 ;i <= n ; i++){
    if( a[u][i] == 1 )
    {   a[i][u] = 0;
        a[u][i] = 0 ;
     inset(i);
    }
    }
ends[tc.top()] = ++cnt;
tc.pop();
if(tc.empty())return;
}
int main(){
int i , j , k , m , t;
scanf("%d",&n);
for(i = 0  ; i < n ; i ++){
    scanf("%d%d",&m,&k);
    while(k--){
        scanf("%d",&t);a[m][t] = 1;
    }
}
inset(1);
for(i = 1 ; i <= n ; i++){
    printf("%d %d %d\n",i,begins[i],ends[i]);
}
return 0;
}

C++: #include<iostream>

int main(){

  int n,a;
  std::cin>>n;

  int Adj[100][100],adj[100][100]={0},find[100][2],back[100],depth[100]={0},endflag[100]={0},flag;
  int u[n],k[n],kcou=0,timenow=0,v,pred,prev;
  for(int i=0;i<n;i++){
    std::cin>>u[i];
    std::cin>>k[i];
    for(int j=0;j<k[i];j++){
      std::cin>>Adj[i][j];
    }
  }
	
	/*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    	std::cout<<Adj[i][j]<<" ";
    }
  	std::cout<<"\n";
  }*/
	
	v=0;

	while(timenow<n*2){
		flag=0;
		//std::cout<<find[v][0]<<" "<<find[v][1];
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(endflag[v]==1){
				timenow++;
				find[v][1]=timenow;
				flag=2;
			}
			//std::cout<<flag<<" 2";
		}else{
			v=back[v];
			flag=3;
			//std::cout<<flag<<" 0";
		}

		if(flag==0){
			pred=depth[v];
			depth[v]++;
			prev=v;
			v=Adj[v][pred]-1;
			back[v]=prev;
			//std::cout<<flag<<"\n";
		}else if(flag==1){
			if(endflag[v]==1){
				depth[v]++;
			}else{
				pred=depth[v];
				depth[v]++;
				prev=v;
				v=Adj[v][pred]-1;
				back[v]=prev;
				//std::cout<<v<<"\n";
			}
		}else if(flag==2){
			v=back[v];
			//std::cout<<flag<<"\n";
		}
		if(depth[v]>k[v]-1){
			endflag[v]=1;
		}
		
	}
	
	
	
	
  for(int i=0;i<n;i++){
     std::cout<<i+1<<" "<<find[i][0]<<" ";
     std::cout<<find[i][1]<<"\n";
    //std::cout<<"\n";
  }

  return 0;
}

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

struct Vertex {
	int id;
	vector<int> vertices;
	int visited;
	int completed;
};

int getNext(Vertex vertices[], int id){
	Vertex v = vertices[id-1];
	int size = v.vertices.size();
	for(int i=0;i<size;i++){
		int nId = v.vertices[i];
		if (vertices[nId-1].visited==-1){
			return nId;
		}
	}
	return -1;
}

void dfs(int n, Vertex vertices[]){
	
	int time = 0;

	for(int i=0;i<n;i++){
		stack<int> st;
		if(vertices[i].visited==-1){
			st.push(vertices[i].id);
		}
		while(!st.empty()){
			int id=st.top();
			if(vertices[id-1].visited==-1){
				vertices[id-1].visited=++time;
			}
			int nId=getNext(vertices,id);
			if(nId!=-1){
				vertices[nId-1].visited=++time;
				st.push(nId);
			} else {
				vertices[id-1].completed=++time;
				st.pop();
			}
		}
	}
}

int main(){
	

	int n;
	cin >> n;
	Vertex vertices[n];

	for(int i=0;i<n;i++){
	
		int id;
		cin >> id;
		vertices[i].id = id;
		vertices[i].visited = -1;
		vertices[i].completed = -1;

		int cnt;
		cin >> cnt;
		for(int j=0;j<cnt;j++){
			cin >> id;
			vertices[i].vertices.push_back(id);
		}
	}
	
	dfs(n,vertices);
	
	for(int i=0;i<n;i++){
		Vertex v = vertices[i];
		cout << v.id << " ";
		cout << v.visited << " ";
		cout << v.completed << endl;
	}

	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

#define int long long
#define dotimes(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

signed main() {
  int n = rint();
  vector<vector<int> > edges(n);
  dotimes(i, n) {
    int u = rint() - 1;
    int k = rint();
    edges[u].reserve(k);
    dotimes(j, k)
      edges[u].emplace_back(rint() - 1);
    sort(edges[u].begin(), edges[u].end());
  }
  int d[n], f[n];
  fill(d, d + n, 0);
  fill(f, f + n, 0);
  int t = 1;
  function<void(int)> rec;
  rec = [&](int u) {
    if (d[u])
      return;
    d[u] = t++;
    for (auto v : edges[u])
      rec(v);
    f[u] = t++;
  };
  dotimes(u, n) {
    rec(u);
    printf("%lld %lld %lld\n", u+1, d[u], f[u]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int adj_matrix[N_MAX+1][N_MAX+1];

int d[N_MAX+1];
int f[N_MAX+1];

stack<int> route;

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

    int n;
    cin >> n;

    int id, k, v;
    FOR(i,0,n) {
        cin >> id;
        cin >> k;
        FOR(j,0,k) {
            cin >> v;
            adj_matrix[id][v] = 1;
        }
    }

    const int TIMELIMIT = 2 * n;

    int cur = 1;
    route.push(0);

    FOR(t,1,TIMELIMIT) {
        if (!d[cur]) {
            d[cur] = t;
        }
        int next = 0;
        FOR(i,1,n+1) {
            if (adj_matrix[cur][i] && !d[i]) {
                next = i;
                break;
            }
        }
        if (next == 0) {
            f[cur] = t + 1;
            cur = route.top();
            route.pop();
        } else {
            route.push(cur);
            cur = next;
        }
    }

    FOR(i,1,n+1) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}