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 <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <stack>
#include <map>

using namespace std;

template<typename ISTREAM>
void readGraphListAsMatrix(const size_t n, ISTREAM& cin, vector< vector<int> >& graphMatrix) {
	graphMatrix = vector< vector<int> >(n, vector<int>(n, 0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u;
		cin>> k;
		for (size_t j = 0; j != k; ++j) {
			size_t v;
			cin >> v;
			graphMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
}

void printMatrix(const vector< vector<int> >& grapthMatrix) {
	const size_t n = grapthMatrix.size();
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}
}


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > graphMatrix;
	readGraphListAsMatrix(n, cin, graphMatrix);
	stack<int> visitedNodeIDs;
	int time = 0;
	vector<pair<int, int>> timeStamp(n,make_pair(0,0));//pair<初回訪問時刻, 完了時刻>
	vector<vector<int>::iterator> searchBeginPos; {
		searchBeginPos.reserve(n);
		for (auto& v : graphMatrix)searchBeginPos.push_back(v.begin());
	}

	vector<pair<int, int>>::iterator visitTimeSearchPos = timeStamp.begin();
	while (
		(visitTimeSearchPos = find_if(visitTimeSearchPos, timeStamp.end(), [&](const pair<int, int>& df) {return df.first == 0; }))
		!= timeStamp.end()) {
		visitedNodeIDs.push(distance(timeStamp.begin(), visitTimeSearchPos));
		visitTimeSearchPos->first = ++time;
		++visitTimeSearchPos;
		while (!visitedNodeIDs.empty()) {
			const int nodeID_1 = visitedNodeIDs.top();
			vector<int>& neighbourNodeList = graphMatrix.at(nodeID_1);
			vector<int>::iterator result = find(searchBeginPos.at(nodeID_1), neighbourNodeList.end(), 1);
			if (result != neighbourNodeList.end()) {
				const int nextVisitID_1 = distance(neighbourNodeList.begin(), result);
				timeStamp.at(nextVisitID_1).first = time + 1;
				for (auto&v : graphMatrix) v.at(nextVisitID_1) = 0;
				visitedNodeIDs.push(nextVisitID_1);
				searchBeginPos.at(nodeID_1) = result + 1;
			}
			else {
				//隣接リストに検索対象なし
				timeStamp.at(nodeID_1).second = time + 1;
				visitedNodeIDs.pop();
			}
			++time;
		}
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << timeStamp.at(i).first << " " << timeStamp.at(i).second << endl;
	}
}

int main()
{

	execute(cin);

	return 0;
}

C++: // C++ 14
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define INTMAX (1 << 21)
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(Int x = start; x > end; x--)

using namespace std;

#define MAX 100


void dfs(vector<Int> vs[], Int n) {
    Int t = 0;
    bool visited[n];
    Int ds[n];
    Int fs[n];
    
    loop(i,0,n) {
        visited[i] = false;
        ds[i] = fs[i] = 0;
    }
    
    stack<Int> S;
    loop(i,0,n) {
        if (visited[i]) continue;
        
        S.push(i);
        visited[i] = true;
        ds[i] = ++t;
    
loop:
        while (!S.empty()) {
            Int i = S.top();
            for (auto c: vs[i]) {
                if (visited[c]) continue;
                S.push(c);
                visited[c] = true;
                ds[c] = ++t;
                goto loop;
            }
            
            S.pop();
            fs[i] = ++t;
        }
    }
    
    loop(i,0,n) cout << i+1 << " " << ds[i] << " " << fs[i] << endl;
}


int main(void){
    Int n, x, cc, c;
    cin >> n;
    vector<Int> vs[n];
    loop(i,0,n) {
        cin >> x >> cc;
        loop(j,0,cc) {
            cin >> c;
            vs[x-1].push_back(c-1);
        }
        
    }
    dfs(vs, n);
}

C++: #include <iostream>


int D[100];
int F[100];
int V[100][100];

int cnt = 0;
int n;

void dfs(int r) {
    D[r] = ++cnt;
    for (int i = 0; i < n; i++) {
        if ((V[r][i] == 1) && (D[i] == 0)) {
            dfs(i);
        }
    }
    F[r] = ++cnt;
}

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }

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

    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << " " << F[i] << std::endl;
    }
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define WHITE 0
#define GRAY 1
#define BLACK 2
//ios::sync_with_stdio(false);
typedef long long LL;
using namespace std;
const int MAXN = 110;
int n, mapp[MAXN][MAXN], color[MAXN], d[MAXN], f[MAXN], tt;

void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for(int i = 0; i < n; i++) {
		if(mapp[u][i] == 1 && color[i] == WHITE) {
			dfs_visit(i);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs() {
	tt = 0;
	memset(color, 0, sizeof(color));
	for(int i = 0; i < n; i++) {
		if(color[i] == WHITE) {
			dfs_visit(i);
		}
	}
	for(int i = 0; i < n; i++) {
		printf("%d %d %d\n", i+1, d[i], f[i]);
	}
}

int main() {
	int u, v, k;	
	cin >> n;
	memset(mapp, 0, sizeof(mapp));
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		while(k--) {
			cin >> v;
			v--;
			mapp[u][v] = 1;
		}
	}
	dfs();
	return 0;
}