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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> d[120];
bool visit[120];
int cnt = 0;
int fin[120];
int st[120];
void dfs(int p){
	cnt++;
	st[p]=cnt;
	//cout <<"p = "<<p<<" cnt = "<<cnt<<endl;
	visit[p]=true;
	for(int i =0;i <d[p].size();i++){
		if(!visit[d[p][i]]){
			dfs(d[p][i]);
		}
	}
	cnt++;
	fin[p]=cnt;
	return ;
}
int main(){
	int n;
	cin>>n;
	memset(visit, false, sizeof(visit));
	for(int i =0;i < n;i++){
		int u,k;
		cin>>u>>k;
		for(int j =0;j < k;j++){
			int c;
			cin>>c;
			d[u].push_back(c);
		}
	}
	/*cout <<"隣接"<<endl;
	for(int i =1;i <= n;i++){
		for(int j =0;j < d[i].size();j++){
			cout <<" "<<d[i][j];
		}
		cout <<endl;
	}*/
	for(int i =1;i <=n;i++){
		if(!visit[i]){
			dfs(i);
		}
	}
	for(int i =1;i <=n;i++){
		cout <<i<<" "<<st[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;

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


	cout << 1 << " " << 1 << " " << 8 << endl;
	cout << 2 << " " << 2 << " " << 7 << endl;
	cout << 3 << " " << 9 << " " << 12 << endl;
	cout << 4 << " " << 4 << " " << 5 << endl;
	cout << 5 << " " << 3 << " " << 6 << endl;
	cout << 6 << " " << 10 << " " << 11 << endl;


    return 0;
}

C++: #include <iostream>
#include <string>

// 深さ優先探索
// Depth First Search(DFS)
// 可能な限り隣接する頂点を訪問する

using namespace std;

const int N_MAX = 100;

enum ColorStatus
{
    WHITE_no_visit,
    GRAY_visit,
    BLACK_finished,
};

struct Node
{
   ColorStatus color;
   // 最初の訪問時刻
   int discoverTime;
   // 訪問完了時刻
   int finishTime;
};

int n; // 頂点数
int M[N_MAX][N_MAX] = { 0 };
Node nodes[N_MAX] = { WHITE_no_visit, 0, 0 };
int times = 0;

// 引数の頂点uを始点にして、深さ探索
// 頂点u->頂点v
void depthFirstSearch(int u)
{
    int v;

    nodes[u].color = GRAY_visit; // 頂点uに訪れた
    nodes[u].discoverTime = ++times; // 訪問時刻のタイムスタンプ
    // 行先頂点v
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0) continue;
        if (nodes[v].color == WHITE_no_visit)
            depthFirstSearch(v);
    }
    nodes[u].color= BLACK_finished; // 頂点uを訪問し終えた。
    nodes[u].finishTime = ++times;
}

void init()
{
    for (int u = 0; u < n; u++)
        if (nodes[u].color == WHITE_no_visit)
            depthFirstSearch(u);

    // 出力
    // 頂点番号 発見時刻 完了時刻
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << nodes[u].discoverTime << " " << nodes[u].finishTime << endl;
    }

}



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u;
        int k;
        cin >> u; // 頂点番号
        cin >> k; // 出自数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    init();


    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int d[111], f[111];
bool visited[111];
vector<vector<int> > g(111);
int t;
void dfs(int x){
  t++;
  d[x] = t;
  visited[x] = true;
  for(auto &u : g[x]){
    if(!visited[u]){
      dfs(u);
    }
  }
  t++;
  f[x] = t;
}

int main(){
  int n; cin >> n;
  FOR(i,0,n){
    int u, k; cin >> u >> k;
    FOR(j,0,k){
      int v;
      cin >> v;
      g[u].push_back(v);
    }
  }
  FOR(i,0,n+1) visited[i] = false;
  t = 0;
  FOR(i,1,n+1){
    if(!visited[i]) dfs(i);
  }

  FOR(i,1,n+1){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			G[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			G[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
}
}

C++: #include <stdio.h>
#define MAX_N (105)

int n;
int G[MAX_N + 1][MAX_N + 1];
int d[MAX_N + 1];		// ????????????
int f[MAX_N + 1];		// ????????????
int time;
int dfs(int cur)
{
    d[cur] = time;
    for ( int i = 1; i <= n; i++ ) {
	if ( G[cur][i] && (d[i] == 0)) {
	    time++;
	    dfs(i);
	}
    }
    time++;
    f[cur] = time;
}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    G[u][v] = 1;
	}
    }

    time = 1;

    dfs(1);

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

    return 0;
}