Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
#include <cassert>
#include <cmath>
using namespace std; typedef long long ll; ll an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P;
vector<int> v[100];
int ts, st[100], ed[100];

void dfs(int from) {
  if (st[from] == -1) st[from]=++ts;
  else return;
  for(int to:v[from]) {
    if (st[to] == -1) dfs(to);
  }
  if (ed[from] == -1) ed[from]=++ts; return;
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;i++) {
    int _, k; cin>>_>>k;
    for(int j=0;j<k;j++) {
      int x; cin>>x; x--;
      v[i].push_back(x);
    }
  }
  ts=0;
  fill(st, st+n, -1); fill(ed, ed+n, -1);
  for(int i=0;i<n;i++) dfs(i);
  for(int i=0;i<n;i++) {
    cout<<i+1<<" "<<st[i]<<" "<<ed[i]<<endl;
  } return 0;
}

C++: #include <iostream>

using namespace std;

int a[124][124] = {{}};
int start[124] = {};
int e[124] = {};
int c = 0;
int n;
void dfs(int k){
  if(start[k] != 0) return;
  c++;
  start[k] = c;

  for(int i = 0;i < n;i++){
    if(a[k][i] == 1){
      dfs(i);
    }
  }
  c++;
  e[k] = c;
}
int main(){

  int u,k,x;
  cin >> n;



  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> x;
      a[u - 1][x - 1] = 1;
    }
  }


  for(int i = 0;i < n;i++)  dfs(i);

  for(int i = 0;i < n;i++){
    cout << i + 1 << " " << start[i] << " " << e[i] << endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

vector<bool> seen;
vector<int> first;
vector<int> last;

void dfs(const vector<vector<int>> &g, int v, int &ptr){
  first[v] = ptr++;
  seen[v] = true;
  
  for(int i : g[v]){
    if(seen[i]) continue;
    dfs(g,i,ptr);
  }
  
  last[v] = ptr++;
}

int main() {
  int n;
  cin >> n;
  seen.assign(n,false);
  first.resize(n);
  last.resize(n);
  
  vector<vector<int>> g(n);
  
  rep(i,n){
    int u, k;
    cin >> u >> k;
    u--;
    vector<int> v(k);
    rep(j,k){
      cin >> v[j];
      v[j]--;
      g[u].push_back(v[j]);
    } 
  }
  int ptr = 1;
  rep(i,n){
    if(first[i] == 0){
      dfs(g,i,ptr);
    }
  }


  rep(i,n){
    cout << i + 1 << ' ' <<first[i] << ' ' << last[i] << endl;
  } 
}

C++: #include <iostream>
using namespace std;
int a[100][100]={},f[100]={},d[100]={},T[200]={};
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++){
			cin>>a[u][j];
		}
	}
	T[1]=1;
	f[1]=1;
	for(int time=2;time<=2*n;time++){
		for(int j=0;j<100;j++){
			if(a[T[time-1]][j]==0){
				d[T[time-1]]=time;
				T[time]=T[f[T[time-1]]-1];
				break;
			}
			else if(f[a[T[time-1]][j]]==0){
				f[a[T[time-1]][j]]=time;
				T[time]=a[T[time-1]][j];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<f[i]<<" "<<d[i]<<endl;
	}
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = search(array, A, 1, n, 0);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}

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

vector<int>G[102];
int d[102],f[102];
bool vis[102];
int V;
int cur=0;
/*
void dfs(int id){
    cur++;
    d[id]=cur;
    vis[id]=true;
    for(int i=0;i<G[id].size();i++){
        if(!vis[G[id][i]])
            dfs(G[id][i]);
    }
    f[id]=cur;
}
*/
stack<int> s;
void dfs_visit(int id){
    s.push(id);
    cur++;
    d[id]=cur;
    while(!s.empty()){
        int u=s.top();
        int nex=-1;
        for(int i=0;i<G[u].size();i++){
            if(!vis[G[u][i]]) {
                nex=G[u][i];
                break;
            }
        }
        cur++;
        if(nex==-1){
            s.pop();
            f[u]=cur;
            vis[u]=true;
        }
        else{
            d[nex]=cur;
            s.push(nex);
        }
    }
}

void dfs(){
	int i;
    for(i=1;i<=V;i++){
        if(!vis[i]) dfs_visit(i);
    }
    for(i=1;i<=V;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}
int main(){
    cin>>V;
    memset(vis,false,sizeof(vis));
    for(int i=1;i<=V;i++){
        int id,k;
        cin>>id>>k;
        while(k--){
            int out;
            cin>>out;
            G[id].push_back(out);
        }
        sort(G[id].begin(),G[id].end());
    }
    dfs();
    return 0;
}