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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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 <iostream>
using namespace std;

enum Color {
	WHITE,
	GRAY,
	BLACK,
};

class dfs {
public:
	dfs(bool matrixT[][100], Color colorT[], int ts_F[], int ts_L[], int verNum) {
		for (int i = 0; i < verNum; i++) {
			for (int j = 0; j < verNum; j++)
				matrixTable[i][j] = matrixT[i][j];
		}
		verNumber = verNum;
	}

	void DFS(int nowVerVal) {
		colorTable[nowVerVal] = GRAY;
		++ttl;
		ts_first[nowVerVal] = ttl;

		for (int nextVer = 0; nextVer < verNumber; nextVer++) {
			if (matrixTable[nowVerVal][nextVer] == false) continue;
			if (colorTable[nextVer] != WHITE) continue;
			DFS(nextVer);
		}
		colorTable[nowVerVal] = BLACK;
		++ttl;
		ts_last[nowVerVal] = ttl;
	}

	void DFS_Init() {
		ttl = 0;
		for (int i = 0; i < verNumber; i++)
			colorTable[i] = WHITE;

		for (int i = 0; i < verNumber; i++)
			if (colorTable[i] == WHITE) DFS(i);
	}

	void print() {
		for (int i = 0; i < verNumber; i++) {
			cout << i + 1 << " " << ts_first[i] << " " << ts_last[i] << endl;
		}
	}
private:
	bool matrixTable[100][100];
	Color colorTable[100];
	int ts_first[100];
	int ts_last[100];
	int verNumber;
	int ttl;
};

int main() {
	int verNum; //num??????????????°???value????????????????????????????????¨???
	bool matrixTable[100][100]; //???????????¨??????????????????
	Color colorTable[100];
	int timeStamp_first[100];
	int timeStamp_last[100];
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++) {
			matrixTable[i][j] = false;
		}

	for (int i = 0; i < verNum; i++) {
		int verVal, nextVerNum;
		cin >> verVal >> nextVerNum;
		for (int j = 0; j < nextVerNum; j++) {
			int nextVerVal;
			cin >> nextVerVal;
			//0?????????????????´???
			matrixTable[verVal - 1][nextVerVal - 1] = true;
		}
	}

	dfs* d = new dfs(matrixTable, colorTable, timeStamp_first, timeStamp_last, verNum);
	d->DFS_Init();
	d->print();

	return 0;
}

C++: #include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
//   訪問状態     発見    完了
int n,M[101][101];
const int WHITE=0; //未訪問
const int GRAY=1;  //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  scanf("%d",&n);
  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;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) //訪問していないか
      dfs(i); //iを始点に
  }
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int tim;
int n;
void visit(int);

int main(){
	tim=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1;
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1;
		}
	}
	visit(0);
	// ??¨???????????????????????????????????°?¨????????????¨??????
	for(i=0;i<n;i++){
		cout<< i+1 << " "<<d[i]<< " "<<f[i];
		cout<<endl;
	}
	return 0;
}

void visit(int k){
	int i;
	d[k]=++tim;
	for(i=0;i<n && f[k]==-1;i++){
		if(map[k][i]==1&&d[i]==-1){
			visit(i);
		}
	}
	f[k]=++tim;
}

C++: #include<bits/stdc++.h>

using namespace std;
using ll = long long;


int n;
vector<vector<int>> hen;
vector<int> in, out;
vector<bool> seen;

void dfs(int cur, int& tim)
{
    tim++;
    in[cur] = tim;
    seen[cur] = true;
    for(auto i : hen[cur])
    {
        if(seen[i])continue;
        dfs(i, tim);
    }
    tim++;
    out[cur] = tim;
}


int main()
{
    cin >> n;
    hen.resize(n);
    in.resize(n);
    out.resize(n);
    seen.resize(n);
    for(int i = 0; i < n; i++){
        int u,k;cin >> u >> k; u--;
        for(int j = 0; j < k; j++){
            int v; cin >> v; v--;
            hen[u].push_back(v);
        }
        sort(hen[u].begin(), hen[u].end());
    }

    int t = 0;
    for(int i = 0; i < n; i++){
        if(!seen[i])dfs(i,t);
    }

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

C++: #include <iostream>

using namespace std;

#define MAX 100

int n,Time;
int G[MAX][MAX],d[MAX],f[MAX];
bool used[MAX];

void dfs(int v){
  d[v] = Time++;
  used[v] = true;

  for(int i = 0 ; i < n ; i++){
    if(!used[i] && G[v][i]){
      dfs(i);
    }
  }

  f[v] = Time++;
}

int main(){
  cin >> n;

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

  Time = 1;
  for(int i = 0 ; i < n ; i++){
    if(!used[i]){
      dfs(i);
    }
  }

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

  return 0;
}

C++: #include<queue>
#include<stack>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
 
int n, dd[100], f[100], tmap[100][100];
int color[100], t = 1;
stack<int> S;
 
int a(){
    int d = S.top();
    dd[d] = t;
    t++;
    color[d] = 1;

    for (int i = 1; i <= n; i++){
        if (color[i] == 0 && tmap[d][i] == 1){
            S.push(i);
            a();
        }
    }

    f[d] = t;
    t++;
    return 0;
}
 
 
int main(){
    cin >> n;
    for (int i = 0; i < 100; i++){
        dd[i] = f[i] = color[i] = 0;
        for (int j = 0; j < 100; j++){
            tmap[i][j] = 0;
        }
    }
 
    int u, k, v;
 
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v;
            tmap[u][v] = 1;
        }
    }
    for(int i=1;i<=n;i++){
        if(color[i] == 0){
             S.push(i);
             a();
         }
    }
    for (int i = 1; i <= n; i++){
        cout << i << " " << dd[i] << " " << f[i] << endl;
    }
    return 0;
}