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<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>

int main(){
    int n;
    scanf("%d",&n);
    int a[n+1][n+1];
    int i,j;
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)a[i][j]=0;
    for(i=1;i<=n;i++){
        int q,k;
        scanf("%d %d",&q,&k);
        for(j=1;j<=k;j++) {
            int p;
            scanf("%d",&p);
            a[q][p]=1;
        }
    }
    int time=0;
    std::stack<int>S;
    int ans[n+1][3];
    
    
    
    S.push(1);
    time++;
    ans[1][1]=time;
    
    int color[n+1];
    color[1]=1;
    for(i=2;i<=n;i++)color[i]=0;//0??????????¨????
    int lastcheck=0;
    
    while(lastcheck==0){
    while(S.size()>=1){
        int flag=0;//flag=0??????pop
        for(i=1;i<=n;i++){
            if(i!=S.top()&& a[S.top()][i]==1 &&color[i]==0){
                S.push(i);
                color[i]=1;
                time++;
                ans[i][1]=time;
                flag=1;
                break;
            }
        }
        if(flag==0){
            time++;
            ans[S.top()][2]=time;
            S.pop();
        }
    }
        lastcheck=1;
        for(i=1;i<=n;i++)if(color[i]==0){
            lastcheck=0;
            break;
        }
        S.push(i);
        time++;
        ans[i][1]=time;
        
    }
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,ans[i][1],ans[i][2]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int n, m[100][100] = { 0 }, d[100] = { 0 }, t = 0, nt[100] = { 0 }, f[100] = { 0 };
int color[100] = { WHITE };

int next(int u) {
	FOR(i, nt[u], n) {
		nt[u] = i + 1;
		if (m[u][i]==1){ return i; }
	}
	return -1;
}

int dfs(int r) {
	stack<int>S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++t;

	while (!S.empty()) {
		int u=S.top();
		int v = next(u); //cout << v << endl;
		if (v != -1) {
			if (color[v]==WHITE)
			{
				S.push(v);
				color[v] = GRAY;
				d[v] = ++t;
			}
		}
		else {
			S.pop();
			color[v] = BLACK;
			f[u] = ++t;
		//	cout << f[v]<<endl;
		}
	}
	return 0;
}
int main()
{
	 cin >> n;
	REP(i, n) {
		int u, k; cin >>u >> k; u--;//
		REP(j, k) {
			int muki; cin >> muki; muki--;//
			m[u][muki] = 1;
			//printf("%d aa%d\n", u, muki);
		}
	}
	REP(i, n) {
		if (color[i] == WHITE) {
			dfs(i);// cout << i << endl;
		}
	}
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vec;
typedef vector<vec> Graph;

Graph G(110);
int T,In[110],Out[110];
bool used[110];

void dfs(int x)
{
	used[x]=true;
	In[x]=++T;
	for(int i=0;i<G[x].size();i++)
		if(!used[G[x][i]])
			dfs(G[x][i]);
	Out[x]=++T;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v;
			scanf("%d",&v);
			G[u].push_back(v);
		}
	}
	memset(used,false,sizeof(used));
	T=0;
	for(int i=1;i<=n;i++)
		if(!used[i])
			dfs(i);
	for(int i=1;i<=n;i++)
		printf("%d %d %d\n",i,In[i],Out[i]);
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int t = 0;
vector<vector<int> > a;
vector<int> d, f;
vector<bool> v;

void dfs(int i) {
  v[i] = true;
  d[i] = ++t;
  for (int j : a[i]) {
    if (!v[j]) {
      dfs(j);
    }
  }
  f[i] = ++t;
}

int main() {
    int n; cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        int u; cin >> u; u--;
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v; v--;
            a[i].push_back(v);
        }

    }
    v.resize(n, false);
    d.resize(n);
    f.resize(n);

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

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	book[u] = red;
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
			{
				if (book[*it - 1] == black)
				{
					dfs(*it - 1);
				}
			}
			book[u] = white;
			t[u][1] = ++tot;
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u, k, v;
		scanf("%d%d", &u, &k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for (int i = 0; i < n; i++)
		if (book[i] == black)
			dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d\n", i + 1, t[i][0], t[i][1]);;
	}
	return 0;
}