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 <bits/stdc++.h>

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][n] = {};

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

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

    if(st.empty()) {
      t++;
      for (int i = 0; i < n; i++) {
        if(d[i] == 0) {
          st.push(i);
          break;
        }
      }
    }

    t++;
  }

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

}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,u,k,p,d[105],f[105],tt=0;
bool adm[105][105],se[105];

void makemap()
{
    memset(adm,false,sizeof(adm));
    memset(se,true,sizeof(se));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
}

void dfs(int p)
{
    d[p]=++tt;
    se[p]=false;
    for(int i=1;i<=n;i++)
        if(adm[p][i]&&se[i])dfs(i);
    f[p]=++tt;
}

int main()
{
    makemap();
    for(int i=1;i<=n;i++)if(se[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time = 1) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) {
		if (!checked[adjacent[now][i]]) {
			time = dfs(adjacent[now][i], time + 1);
		}
	}
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(n);

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			adjacent[u - 1].push_back(v-1);
		}
	}
	
	int time = dfs(0, 1)+1;
	for (int i = 0; i < n; i++) {
		if (!checked[i])time = dfs(i, time)+1;
	}
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
	}

}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

vector<vector<size_t>> g;
vector<size_t> gs;
vector<size_t> gf;
stack<size_t> st;

size_t dfs(size_t i, size_t t) {
	st.push(i);
	while (!st.empty()) {
		auto j = st.top();
		vector<size_t>& l = g.at(j);
		if (gs.at(j) != 0) {
			if (gf.at(j) == 0)
				gf.at(j) = ++t;
			st.pop();
			continue;
		}
		gs.at(j) = ++t;
		for (ll k = l.size() - 1; k >= 0; --k) {
			auto n = l.at(k);
			if (gs.at(n) == 0) {
				st.push(n);
			}
		}
	}
	return t;
}

int main() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	size_t n;
	cin >> n;
	g.resize(n);
	gs.resize(n);
	gf.resize(n);

	REP(i, n) {
		size_t u, k;
		cin >> u >> k;
		u -= 1; // 0 base
		g.at(u).resize(k);
		REP(j, k) {
			cin >> g.at(u).at(j);
			g.at(u).at(j)--;
		}
	}
	size_t t = 0;
	for (;;) {
		size_t target = INF;
		REP(i, n) {
			if (gs.at(i) == 0) {
				target = i;
				break;
			}
		}
		if (target == INF) break;
		t = dfs(target, t);
	}
	
	REP(i, n) {
		cout << i + 1 << " " << gs.at(i) << " " << gf.at(i) << ::endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !start[graph[num][i]] && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

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


class Graph {
public:
    std::vector<int> d, v;
    std::vector<std::vector<int>> arr;
    int n;
    int tp = 1;

    Graph(int n) : n(n) {
        d = std::vector<int>(n, 0);
        v = std::vector<int>(n, 0);
        arr = std::vector<std::vector<int>>(n);
    }
    
    void depth_search(int i) {
        if (d[i] == 0) {
            d[i] = tp;
            tp++;
            for (auto j : arr[i]) {
                depth_search(j - 1);
            }
            v[i] = tp;
            tp++;
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i + 1 << " " << d[i] << " " << v[i] << std::endl;
        }
    }
};


int main() {
    int n;
    std::cin >> n;

    Graph graph(n);
    
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> vs(k);
        
        for (int i = 0; i < k; i++) {
            std::cin >> vs[i];
        }
        graph.arr[u - 1] = vs;
    }

    for (int i = 0; i < n; i++) {
        graph.depth_search(i);
    }

    graph.print();

}