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>
#include <stack>
using namespace std;

#define MAX 100
static const int WHITE = 0; // not visit
static const int GRAY = 1; // visited
static const int BLACK = 2; // searched

int n;
int M[MAX][MAX] = { 0 };
int color[MAX] = { WHITE };
int d[MAX], f[MAX], tt = 0;
int nt[MAX] = { 0 };

// get vertex next u
int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs() {
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE)  dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
	return;
}

int main() {
	cin >> n;

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

	dfs();
	return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
static const int N=100;
enum COLOR{WHITE,GRAY,BLACK};

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u)
{
    for(int v=nt[u];v<n;v++)
    {
        nt[u]=v+1;
        if(M[u][v])return v;
    }
    return -1;
}
void dfs_visit(int r)
{
    for(int i=0;i<n;i++)
    {
        nt[i]=0;
    }
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;

    while(!S.empty())
    {
        int u=S.top();
        int v=next(u);
        if(v!=-1)
        {
            if(color[v]==WHITE)
            {
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}
void dfs()
{
    for(int i=0;i<n;i++)
    {
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;

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

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++: #include <stdio.h>

#define VerticesNum 100
typedef unsigned int uint;

struct output
{
    uint uDiscoverTime;
    uint uFinTime;
}Output;

struct output gstOutput[VerticesNum];
uint uTotalTime = 1;

void DepthFirstSearch(uint pGraph[][VerticesNum], uint uSize, uint uRoot)
{
    if(gstOutput[uRoot].uDiscoverTime == 0)
    {
        gstOutput[uRoot].uDiscoverTime = uTotalTime++;
    }
    else
    {
        return;
    }
    
    for(uint i = 0; i < uSize; i++)
    {
        if((pGraph[uRoot][i] == 1) && (gstOutput[i].uDiscoverTime == 0 ))
        {
            DepthFirstSearch(pGraph, uSize, i);
        }
    }
    gstOutput[uRoot].uFinTime = uTotalTime++;
    
    return;
}

int main(void){
    uint arGraph[VerticesNum][VerticesNum] = {};
    
    uint uVertices;
    scanf("%u", &uVertices);
    
    for(uint i = 0; i < uVertices; i++)
    {
        uint uVertexIdx;
        uint OutDegree;
        scanf("%u", &uVertexIdx);
        scanf("%u", &OutDegree);
        for(uint j = 0; j < OutDegree; j++)
        {
            uint AdjacentVertex;
            scanf("%u", &AdjacentVertex);
            arGraph[uVertexIdx - 1][AdjacentVertex - 1] = 1; 
        }
    }
    /*
    for(uint i = 0; i < uVertices; i++)
    {
        for(uint j = 0; j < uVertices; j++)
        {
            printf("%u", stGraph[i][j]);
            (j < (uVertices - 1))
                ? printf(" ")
                : printf("\n");
        }
    }
    */
    for(uint uRoot = 0; uRoot < uVertices; uRoot++)
    {
        DepthFirstSearch(arGraph, uVertices, uRoot);
    }
    
    for(uint i = 0; i < uVertices; i++)
    {
        printf("%d %d %d\n", i + 1, gstOutput[i].uDiscoverTime, gstOutput[i].uFinTime);
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N;
vector<vector<int>> G(110, vector<int>());
vector<int> d(110), f(110), k(110);
vector<bool> visited(110, false);
int t = 0;

void dfs(int v) {
	visited[v] = true;
	d[v] = t;
	//cout << v << " d[" << v << "]:" << d[v] << " " << t << endl;
	rep(i, k[v]) {
		if(visited[G[v][i]]) continue;
		t++;
		//cout << G[v][i] << " " << t << endl;
		dfs(G[v][i]);
		//cout << G[v][i] << " " << t << endl;
	}
	t++;
	f[v] = t;
	//cout << v << " f[" << v << "]:" << f[v] << endl;
	return;
}

int main() {
	cin >> N;
	rep(i,N) {
		int u;
		cin >> u >> k[i];
		G[i] = vector<int>(k[i]);
		rep(j,k[i]) {
			cin >> G[i][j];
			G[i][j]--;
		}
	}
	rep(i,N) {
		if(visited[i] == false) t++,dfs(i);
	}
	rep(i,N) cout << i+1 << " " << d[i] << " " << f[i] << endl;


  return 0;
}