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++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(0));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
			//t[w].push_back(i);
		}
		sort(t[i].begin(),t[i].end());
	}/*
	for(int i=0;i<n;i++){
		sort(t[i].begin(),t[i].end());
		for(int j=0;j<t[i].size();j++)cout<<t[i][j];
		cout<<endl;
	}
	*/
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	
	while(S.size()||p<n){
		g++;
		if(!S.size()){
			
			for(int i=1;i<n;i++)
				if(!F[i]){
					F[i]=1;
					S.push(i);
					G[i]=g;
					p++;
					break;
				}
			//	cout<<t[S.top()].size();
			//break;
				

		}
		else{
		
		//cout<<p;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
			//if(v==2)cout<<t[v][i]<<"&"<<F[i];
		}
		//cout<<a;
		//if(v==2&&a==-1)break;
		if(a==-1){
			H[S.top()]=g;
			S.pop();
			
			
		}
		else{
			//cout<<"%"<<a<<endl;
			F[a]=1;
			G[a]=g;
			S.push(a);
			p++;
		}
		}
	}
	/*for(int i=0;i<t[S.top()].size();i++)
		cout<<t[S.top()][i];
	cout<<"#"<<t[S.top()][1];
	*/
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int t;
vector<int> G[110], d(110), f(110);

void dfs(int u) {
    d[u] = ++t;
    for (int v: G[u]) {
        if (d[v] == 0) dfs(v); 
    }
    f[u] = ++t; 
}

int main() {
    int n; cin >> n;
    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-1].push_back(v-1);
        }
    }
    for (int u = 0; u < n; u++) {
        if (d[u] == 0) dfs(u);
    }
    for (int u = 0; u < n; u++) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl; 
    }
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int White=0;
static const int Gray=1;
static const int Black=2;

int M[N][N];
int d[N],nt[N],f[N],tt,color[N];
int n;
int next_v(int k){
  for(int i=nt[k];i<=n;i++){
    nt[k]=i+1;
    if(M[k][i]) return i;
  }
  return -1;
}
void dfs_visit(int r){
  stack<int> S;
  S.push(r);
  color[r]=Gray;
  d[r]=++tt;

  while(!S.empty()){
    int u=S.top();
    int v=next_v(u);
    if(v!=-1){
      if(color[v]==White){
        d[v]=++tt;
        S.push(v);
      }
    }else{
      S.pop();
      color[u]=Black;
      f[u]=++tt;
    }
  }
}
void dfs(){
  tt=0;
  for(int i=1;i<=n;i++){
    if(color[i]== White)dfs_visit(i);
  }
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k,v;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      M[u][v]=1;
    }
  }
  dfs();
}