Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=0;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  t++;
  d[now]=t;
  used[now]=true;
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=t;
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)if(!used[i])dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

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

struct graph {
	struct node {vector<int> v; int d = 0, f;};
	map<int, node> nodes;
	int count = 1;

	void read_all() {
		int n, id, k, v;
		cin >> n;
		while (n--) {
			cin >> id >> k;
			while (k--) {
				cin >> v;
				nodes[id].v.push_back(v);
			}
		}
	}
	void traverse(int id) {
		if (nodes[id].d)
			return;
		nodes[id].d = count++;
		for (int x: nodes[id].v)
			traverse(x);
		nodes[id].f = count++;
	}
	void traverse() {
		for (auto n: nodes)
			traverse(n.first);
	}
	void display_all() {
		for (auto n: nodes)
			cout << n.first << " " << n.second.d << " " << n.second.f << endl;

	}
};

int main() {
	graph g;
	g.read_all();
	g.traverse();
	g.display_all();
}

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

class TVertex
{
    int FIndex;
    std::vector<TVertex*> FList;
    int FDiscoveryTime;
    int FFinishTime;

public:
    TVertex(int Index)
     : FIndex(Index), FDiscoveryTime(0), FFinishTime(0)
    {}
    void AddPath(TVertex* Vertex)
    {
        FList.push_back(Vertex);
    }
    void PrintTime(std::ostream& out)const
    {
        out << FIndex << " " << FDiscoveryTime << " " << FFinishTime << std::endl;
    }
    int DepthFirstSearch(int Time)
    {
        if(FFinishTime) return Time;
        FDiscoveryTime = Time++;
        for(std::vector<TVertex*>::iterator It = FList.begin(); It != FList.end(); ++It){
            TVertex* V = *It;
            Time = V->DepthFirstSearch(Time);
        }
        FFinishTime = Time++;
        return Time;
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n+1);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 1);
        assert(Index <= FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v;
            in >> v;
            FTable[Index]->AddPath(FTable[v]);
        }
    }
    void DepthFirstSearch()
    {
        FTable[1]->DepthFirstSearch(1);
    }
    void PrintTime(std::ostream& out)
    {
        for(int i = 1; i < FTable.size(); ++i){
            FTable[i]->PrintTime(out);
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.DepthFirstSearch();
    Graph.PrintTime(std::cout);
    return 0;
    
}