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 <stdio.h>
#define N 100
#define WHITE 0;
#define GRAY 1;
#define BRACK 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for( v = 0; v < n; v++ ){
    if ( M[u][v] == 0 ) { continue; }
    if ( color[v] == WHITE ){
      dfs_visit(v);
    }
  }
  color[u] = BRACK;
  f[u] = ++tt;
  
}

void dfs() {
  int u;
  for ( u = 0; u < n; u++ ) color[u] = WHITE;
  tt = 0;
  
  for ( u = 0; u < n; u++) {
    if (color[u] == WHITE ) { dfs_visit(u); }
  }
  for ( u = 0; u < n; u++ ) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k, i, j;
  
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ) M[i][j] = 0;
  }
  
  for ( i = 0; i < n; i++ ) {
    scanf("%d %d", &u, &k );
    u--;
    for ( j = 0; j < k; j++ ) {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
    
    dfs();
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int times;
vector<vector<int>> lists;
vector<int> stampA;
vector<int> stampB;

void dfs(int point){
    times++;
    stampA.at(point-1)=times;
    for(int i=0;i<(int)lists.at(point-1).size();i++){
        if(stampA.at(lists.at(point-1).at(i)-1)==0) dfs(lists.at(point-1).at(i));
    }
    times++;
    stampB.at(point-1)=times;
    
}

int main(){
    times=0;
    int n;
    cin >> n;
    lists.resize(n,vector<int>());
    stampA.resize(n,0);
    stampB.resize(n,0);
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v;
            cin >> v;
            lists.at(u-1).push_back(v);
        }
    }
    
    for(int i=0;i<n;i++){
        if(stampA.at(i)==0) dfs(i+1);
    }
    
    for(int i=0;i<n;i++){
        cout << i+1 << " " << stampA.at(i) << " " << stampB.at(i) << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int j,int& clock)
{

    stack<int> S;
    S.push(j);dTime[j]=++clock;
    Visited[j]=true;
    while(!S.empty())
    {
        int p=S.top(); //???????????¶??????
        if(Adjacency[p].size()==0)
        {
            S.pop();
            fTime[p]=++clock;
            continue;
        }
        int i=0;
        if(Adjacency[p].size())
          while(Visited[Adjacency[p][i]]==true)
          {
            i++;
            if(i==Adjacency[p].size()) //???????°??????????????±?????????????
            {
                S.pop();
                fTime[p]=++clock;
                break;
            }
          }
        if(i==Adjacency[p].size()) continue;
        //if founded
        S.push(Adjacency[p][i]); dTime[Adjacency[p][i]]=++clock;
        Visited[Adjacency[p][i]]=true;
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
using namespace std;

const int INF=1e9;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;

int n;
vector<vector<int> > G(100,vector<int>(100,0));
vector<int> d(100,0),f(100,0);
int t=1;
void dfs(int u){
    d[u]=t++;
    for(int v=0;v<n;v++){
        if(G[u][v]==1&&d[v]==0){
            dfs(v);
        }
    }
    f[u]=t++;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int u,k;cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            int v;cin>>v;
            v--;
            G[u][v]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(d[i]==0){
            dfs(i);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}