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
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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>
using namespace std;
bool A[105][105],vist[105]={0};
int d[105],f[105],n,t=0;

void dfs(int v){
	d[v] = ++t;
	vist[v] = 1;
	for(int i=1;i<=n;i++)
		if(A[v][i] && !vist[i])		
			dfs(i);
	f[v] = ++t;  
}
int main()
{	
	memset(A,0,sizeof(A));
	int v,u,du;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>v>>du;
		while(du--)
			cin>>u,
			A[v][u] = 1;
	}
	for(int i=1;i<=n;i++)
		if(!vist[i]) dfs(i);
	for(int i=1;i<=n;i++)
		printf("%d %d %d\n",i,d[i],f[i]);
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
 
#define WHITE 10000
#define BLACK 10001
#define GRAY 10002
#define TRUE 1
#define FALSE 0
#define NUL NULL
 
void dfs(void);
void visit(int);
void push(int);
void pop(void);
int isEmpty(void);
 
int v[101][101],s[101],time1,n;
int *d,*f,*color;
int top = 0;
 
int main(){
  int u,i,j,w,k;
 
  scanf("%d",&n);
 
  d = malloc(sizeof(int) * (n + 1));
  f = malloc(sizeof(int) * (n + 1));
  color = malloc(sizeof(int) * (n + 1));
 
  for(i = 1;i <= n;i++){
    scanf("%d %d",&u,&k);
    for(j = 1;j <= k;j++){
      scanf("%d",&w);
      v[i][w] = 1;
    }
  }
 
  dfs();
 
  for(i = 1;i <= n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
 
  return 0;
}
 
void dfs(){
  int i = 1,j = 1;
  for(i = 1;i <= n;i++){
      color[i] = WHITE;
  }
 
  time1 = 0;
 
  for(i = 1;i <= n;i++){
    if(color[i] == WHITE){
      visit(i);
    }
  }    
 
}
 
void visit(int r){
  int u,vv=NUL,i;
 
  push(r);
  color[r] = GRAY;
  d[r] = ++time1;
 
  while(isEmpty() == FALSE){
    vv=NUL;
    u = s[top];
    for(i = 1;i <= n;i++){
    if(v[u][i] == 1 && color[i] == WHITE){
      vv = i;
      break;
    }
     
    }
    if(vv != NUL){
      if(color[vv] == WHITE){
    push(vv);
    color[vv] = GRAY;
    d[vv] = ++time1;
      }
    }
    else{
      pop();
      color[u] = BLACK;
      f[u] = ++time1;
    }
  }
}
 
void push(int x){
  top++;
  s[top] = x;
}
 
int isEmpty(){
  if(top == 0){
    return TRUE;
  }
  else{
    return FALSE;
  }
}
 
void pop(){
  top--;
}

C++: #include <stdio.h>
#define N 100
#define W 0
#define X 1
#define Z 2

int n,m[N][N];
int c[N],d[N],f[N],tt;

void dfs_visit(int u){
  int i;
  c[u] = X;
  ++tt;
  d[u] = tt;
  for(i=0;i<n;i++){
    if(m[u][i] == 0) continue;
    else if(c[i]==W){
      dfs_visit(i);
    }
  }
  c[u]=Z;
  ++tt;
  f[u]=tt;
}

void dfs(){
  int i;
  for(i=0;i<n;i++){
    c[i] = W;
  }
  tt = 0;

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

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++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  time[102][2];
int ct = 1;
inline void search(int t) {
	if(!time[t][0]) time[t][0] = ct++;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		time[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {
	for (int i = 1; i <= n; i++) {
		time[i][0] = 0;
	}
	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	search(1);
	for (int i = 1; i <= n; i++) {
		cout << i << " " << time[i][0] << " " << time[i][1] << endl;
	}
	return 0;
}

C++: n=int(input())

l=[[0 for i in range(n)] for j in range(n)]##静的確保 隣接行列
d=[0 for i in range(n)]##発見
f=[0 for i in range(n)]##完了
stack=[]##スタック
check=[]

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1
##print("---隣接行列---")
##print(l)

time=1
d[0]=1
stack+=[1]
check+=[-1]

while len(stack)!=0:
    ##print("----------while---------")
    for i in range(n):
        if l[stack[-1]-1][i]==1 and not i+1 in check:
            time+=1
            d[i]=time
            stack+=[i+1]

           ## print("stack:",stack)
           ## print("d[",i,"]:",d[i])
            break
        elif i==n-1:
##最深    
            check+=[stack[-1]]
            time+=1
            f[stack.pop()-1]=time

            ##print("f[",i,"]:",f[i])
            ##print("check:",check)
            


for i in range(n):
    print(i+1," ",d[i]," ",f[i])

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