Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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

ll N = 100;
vector<ll> ans1;
vector<ll> ans2;
vector<bool> seen;
ll C = 0;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}


void dfs(vector< vector<ll> > &G, int v) {
  seen[v] = true;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    ans1[next_v] = ++C;
    //printf("ans1[%d] = %d\n", next_v+1, C);
    dfs(G, next_v); // 再帰的に探索
    ans2[next_v] = ++C;
    //printf("ans2[%d] = %d\n", next_v+1, C);
  }
}

int main() {
  cin >> N;
  vector< vector<ll> > G(N);
  G.resize(N);
  seen.resize(N, false);
  ans1.resize(N, 0);
  ans2.resize(N, 0);
  int k;
  int tmp;
  rep(i, N) {
    cin >> tmp >> k;
    rep(j, k) {
      int tmp;
      cin >> tmp;
      G[i].push_back(tmp-1);
    }
  }

  rep(i, N) {
    if (!seen[i]) {
      ans1[i] = ++C;
      dfs(G, i);
      ans2[i] = ++C;
    }
  }
  rep(i, N) {
    cout << i+1 << " " << ans1[i] << " " << ans2[i] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
struct Node{
  int u;
  int k;
  int v[99];

  int start;
  int finish;
};

int deep(Node nod[],int x,int count){
  if(nod[x].start)
    return count;

  nod[x].start=(++count);
  for(int i=0; i<nod[x].k; i++)
    count = deep(nod,nod[x].v[i]-1,count);

  nod[x].finish= (++count);
  return count;
}

int main(){
  int n,count=0;
  Node nod[100];

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> nod[i].u >> nod[i].k;
    
    for(int j=0; j<nod[i].k; j++)
      cin >> nod[i].v[j];
    
    nod[i].start=0;
    nod[i].finish=0;
  }

  for(int i=0; i<n; i++)
    count = deep(nod,i,count);
  
  for(int i=0; i<n; i++){
    cout << nod[i].u << " " << nod[i].start << " " << nod[i].finish << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x,head=0;
  
  memset(find_t,0,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    for(int l=0;l<cnt;l++){
      cin>>x;
      flag[x]=1;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }

  for(int i=1;i<=n;i++){
    if(flag[i]==0){
      head=i;
      break;
    }
  }

  memset(flag,0,sizeof(flag));
  DFS(head);
  Print();
  
  return 0;
}

void DFS(int p){
  if(flag[p]==0){
    find_t[p]=t++;
    flag[p]=1;
  }
  else
    return;
    
  if(lft[p]!=-1)
    DFS(lft[p]);
  if(rht[p]!=-1)
    DFS(rht[p]);

  end_t[p]=t++;
}

void Print(){
  for(int i=1;i<=100;i++){
    if(find_t[i]!=0)
      printf("%d %d %d\n",i,find_t[i],end_t[i]);
  }
}

C++: #include<stdio.h>
#define MAX 102
#define WHITE 0
#define BLACK 1
#define GRAY 2


void init();
void visit(int);

int col[MAX];
int n, t = 0;
int d[MAX],f[MAX],edge[MAX],num[MAX][MAX],G[MAX][MAX];

void init(){

  int i,j;

  for(i = 0; i <= n; i++){
      col[i] = WHITE;
    }

}

void dFSearch(){
  int i;
  for(i = 1; i <= n; i++){
    if(col[i] == WHITE) visit(i);
  }
}

void visit(int u){
  int i,j;

  col[u] = GRAY;
  t += 1;
  d[u] = t;

  for(j = 0; j < n; j++){
    if(G[u][j] == 10) {
      if(col[j+1] == WHITE ){
    visit(j+1);
      }
    }
  }

  col[u] = BLACK;
  t = t + 1;
  f[u] = t;

}


int main(){

  int i,j,k = 0,vertex,number;

  scanf("%d\n",&n);
  init();

  for(i = 1; i <= n; i++){
    scanf("%d %d",&vertex,&edge[i]);
    for(j = 1; j <= edge[i]; j++){
      scanf("%d",&number);
      G[vertex][number-1] = 10;
    }
    scanf("\n");
  }

 dFSearch();

  for(i = 1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }

  return 0;


}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};
int n;
int t = 0;
int d[N] = {0};
int f[N] = {0};

void dfs(int id) {
    ++t;
    // cerr << "begin: " <<  id << " " << t << endl;
    if (d[id] == 0)
        d[id] = t;

    for (int i = 0; i < n; ++i) {
        if (A[id][i] != 0) {
            dfs(i);
        }
    }

    // cerr << "end: " <<  id << " " << t << endl;
    ++t;
    f[id] = t;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

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

    dfs(0);

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

    return 0;
}

C++: #include <iostream>
using namespace std;
int cnt = 1;
void DepthFirstSearch(int now,int n,int a[][],int b[],int c[],int d[]){
  b[now]=1;
  c[now]=cnt;
  cnt++;
    for(int i=0;i<n;i++){
        if(a[now][i] && b[i]!=1){
            DepthFirstSearch(i,n,a,b,c,d);
            cnt++;
        }
    }
  d[now]=cnt;
}
int main(){
  int a[100][100],b[100],c[100],d[100]
  int n,u,m,num;
  cin>>n;
  for(int i = 0;i < n;i++){
    cin>>u>>m;
    for(int j = 0;j < m;j++){
      cin >> num;
      a[u-1][num-1]=1;
    }
  }
    for(int i=0;i<n;i++){
       if(b[i]!=1){
         DepthFirstSearch(i,n,a,b,c,d);
         cnt++;
       }
    }
  
    for(int i=0;i<n;i++){
        cout<< i+1 << " " << c[i] << " " << d[i]<<endl;
    }
  return 0;
  
}