Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include <stdio.h>
int n,M[100][100],C[100],d[100],f[100],t;
void visit(int );
void dfs();
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;
}
void dfs(){
  int i;
  for(i=0;i<n;i++)C[i]=0;
  t=0;
  for(i=0;i<n;i++)if(C[i]==0)visit(i);
  for(i=0;i<n;i++)printf("%d %d %d\n",i+1,d[i],f[i]);
}
void visit(int k){
  int i;
  C[k]=1;
  d[k]=++t;
  for(i=0;i<n;i++){
    if(M[k][i]==0)continue;
    if(C[i]==0)visit(i);
  }
  C[k]=2;
  f[k]=++t;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 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] == BLACK;
    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(void){
    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();
}

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

// 深さ優先探索
vector<bool> seen;
vector<int> start_ptr;
vector<int> end_ptr;
void dfs(const Graph &G, int v, int &ptr) {
    seen[v] = true;
    start_ptr[v]=ptr;
    ptr++;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, ptr); // 再帰的に探索
    }
    end_ptr[v]=ptr;
    ptr++;
}

int main() {
    // 頂点数と辺数
    int N; cin >> N;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        for(int j=0;j<b;j++){
            int v; cin >>v;
        
        G[a-1].push_back(v-1);
        }
    }

    // 全頂点が訪問済みになるまで探索
    seen.assign(N, false);
    int ptr=1;
    start_ptr.resize(N);
    end_ptr.resize(N);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v, ptr); // v が未探索なら v を始点とした DFS を行う
    }
    for(int i=0;i<N;i++){
    cout << i+1 <<" "<<start_ptr[i]<<" "<<end_ptr[i]<< endl;
    }
}

C++: #include<stdio.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 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]=BLACK;
    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();
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

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;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,d[N],f[N],tt;
int color[N],nt[N];
int mp[N][N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(mp[u][v]!=0)return v;
    }
    return -1;
}


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



void dfs(){

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

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