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 <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)
#define UPC(a) (a>='A' && a<='B')
#define LWC(a) (a>='a' && a<='b')

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void sctlld(LL &a,LL &b,LL &c){scanf("%I64d %I64d %I64d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

inline void prd(int a){printf("%d",a);};
inline void prdd(int a,int b){printf("%d %d",a,b);};
inline void prtd(int a, int b, int c){printf("%d %d %d",a,b,c);};
inline void prtlld(LL a, LL b, LL c){printf("%I64d %I64d %I64d",a,b,c);};
inline void prdlld(LL a, LL b){printf("%I64d %I64d",a,b);};
inline void prtlld(LL a){printf("%I64d",a);};

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265


int a[200][200],spos[2000],epos[2000],visit[2000],pos;


void dfs(int now,int n)
{
	//debugd(now);
	spos[now]=pos;
	visit[now]=1;
	pos++;
	for(int i=1 ; i<=n ; i++)
	{
		if(a[now][i]==1 && visit[i]==0)
		dfs(i,n);
	}
	//debugd(now);
	epos[now]=pos;
	pos++;
}

int main()
{
	int c,n,m,b;
	pos=1;
	scd(n);
	forin(i,0,n)
	{
		scdd(c,m);
		forin(j,0,m)
		{
			scd(b);
			a[c][b]=1;			
		}
	}
	
	for(int i=1 ; i<=n ; i++)
	{
		if(visit[i]==0)
		dfs(i,n);
	}
	
	for(int i=1 ; i<=n ; i++)
	printf("%d %d %d\n",i,spos[i],epos[i]);
	return 0;
}

C++: //1908-1930 22m
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000
#define FIND 0
#define END 1

int TimeStump[100][2] = {};//find,end
vector<int> V[100];
stack<int> S;
int time_ = 1;

void DFS(int i){
    if (TimeStump[i][FIND] != 0) return;
    S.push(i);
    TimeStump[i][0] = time_;
    time_++;
    
    REP1(k,V[i].size()){
        if (TimeStump[V[i][k]][FIND] == 0){DFS(V[i][k]);}
    }
    
    S.pop();
    TimeStump[i][1] = time_;
    time_++;
}

int main(){
    INT(N);
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to - 1);
        }
    }
    
    REP1(i,N) DFS(i);
    
    REP1(i,N) printf("%d %d %d\n",i+1,TimeStump[i][0],TimeStump[i][1]);
    return 0;
}

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

int n,p=0,side[101][101],startTime[101],endTime[101],v[101];

void dfs(int x){
  if(!v[x]) {
    v[x]++; startTime[x]=++p;
	for (int i =1; i<n+1; i++) {
      if(side[x][i]) {
        dfs(i);
      }
    }
	endTime[x]=++p;
  }
}

int main(){
	int a,b,c;
	cin>>n;
	for (int i =0; i<n; i++) {
      cin>> a >> b;
      for (int i =0; i<b; i++) {
        cin >> c;
        side[a][c]++;
      }
    }
  
  for (int i =1; i<n+1; i++) {
    if(!v[i]) dfs(i);
  }
  for (int i =1; i<n+1; i++) {
    cout << i << ' ' << startTime[i] << ' ' << endTime[i] << endl;    
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<stack>
#include<vector>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int d[MAX],f[MAX];
int color[MAX];
vector<int> V[MAX];
int tt=0,n=0;
stack<int> S;

void dfs(int x){
  S.push(x);
  d[x]=++tt;
  color[x]=GRAY;
  while(!S.empty()){
    int u=S.top();
    int next=-1;
    for(int i=0;i<V[u].size();i++){
      if(color[V[u][i]]==WHITE){
        next=V[u][i]; break;
      }
    }
    if(next==-1){
      color[u]=BLACK;
      S.pop();
      f[u]=++tt;
      continue;
    }
    color[next]=GRAY;
    S.push(next);
    d[next]=++tt;
  }
}

void begindfs(){
  for(int i=0;i<n;i++){
    if(color[i]==WHITE) dfs(i);
  }
}

int main(){
  int u,v,j;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>v;
    u--;
    for(int k=0;k<v;k++){
      cin>>j;
      j--;
      V[u].push_back(j);
    }
  }
  begindfs();
  for(int i=0;i<n;i++){
    cout<<i+1;
    printf(" %d %d\n",d[i],f[i]);
  }

}