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>
#include <cstdio>
#include <cstdlib>

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n, adj_mat[N][N];
int color[N], d[N], f[N], tt;

int Next(int node_id)
{
    for (int i = 0; i < n; i++) {
        if (adj_mat[node_id][i] == 1 && color[i] == WHITE) {
            return i;
        }
    }
    return -1;
}

void DFS(int node_id)
{
    std::stack<int> S;
    S.push(node_id);
    color[node_id] = GRAY;
    d[node_id] = tt++;

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

void Init(int n)
{
    tt = 1;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
        color[i] = WHITE;
        for (int j = 0; j < n; j++) {
            adj_mat[i][j] = 0;
        }
    }
}

int main(int argc, char *argv[])
{
    scanf("%d", &n);

    Init(n);    

    // make adj matrix
    for (int i = 0; i < n; i++) {
        int node_id, adj_num;;
        scanf("%d", &node_id);
        scanf("%d", &adj_num);
        node_id--;
        for (int j = 0; j < adj_num; j++) {
            int adj_id;
            scanf("%d", &adj_id);
            adj_id--;
            adj_mat[node_id][adj_id] = 1;
        }
    }

    // depth search
    for (int i = 0; i < n; i++) {
        if (color[i] == WHITE) DFS(i);
    }

    // dump adj matrix
    for (int i = 0; i < n; i++) {
        fprintf(stdout, "%d %d %d\n", i+1, d[i], f[i]);
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
#define int ll

int g[105][105], d[105], f[105];
int presenttime = 1, n;
bool is_search[105];

void dfs(int p) {
  d[p] = presenttime++;
  is_search[p] = true; // ??????????????§?????§??????

  for (int i = 0; i < n; i++) {
    if(is_search[i] == false && g[p][i] && p != i) dfs(i);
  }
  if (f[p] == 0) f[p] = presenttime++;
}

signed main(void) {
  int u, k, v;

  fill(is_search, is_search + n, false);

  cin >> n;

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

  int s = 0, i;

   while(1) {
    dfs(s);

    for (i = 0; i < n; i++) {
      if (is_search[i] == false) {
        s = i;
        break;
      }
    }
    if(i == n) break;
   }

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

C++: #include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, 0, count);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << i + 1 << " " << find[i] << " " << done[i] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
using Graph=vector<vector<int>>;

void dfs(int s,Graph graph,vector<int> &d,vector<int> &f,int &flag1,int &flag2)
{
	int n=graph.size();
	d[s]=flag1;
	flag1++;
	for (int i=0;i<n;i++)
	{
		if (graph[s][i]==1 && d[i]==-1) dfs(i,graph,d,f,flag1,flag2);
	}
	f[s]=flag2;
	flag2++;
}
int main()
{
	int n;cin >> n;
	Graph graph(n,vector<int> (n,0));
	int u,k,v;
	for (int i=0;i<n;i++)
	{
		cin >>u;
		cin >>k;
		for (int j=0;j<k;j++)
		{
			cin >>v;
			graph[u-1][v-1]=1;
		}
	}
	int flag1=1,flag2=1;
	vector<int> d(n,-1),f(n-1);
	for (int i=0;i<n;i++)
	{
		if (d[i]==-1) dfs(i,graph,d,f,flag1,flag1);
	}
	
	for (int i=0;i<n;i++)
	{
		cout <<i+1 <<" " << d[i] <<" " << f[i] << endl;
	}
	return 0;
}

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

using namespace std;

int n, u, k, v, d[110], f[110], tim=0;
bool vis[110];
vector<int> adj[110];

void dfs (int p)
{
    tim++;
    vis[p]=true;
    d[p]=tim;
    for (auto u : adj[p])
    {
        if (!vis[u]) dfs(u);
    }
    tim++;
    f[p]=tim;
}

int main()
{
    memset(vis, false, sizeof(vis));
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>u>>k;
        for (int j=0; j<k; j++)
        {
            cin>>v;
            adj[u].push_back(v);
        }
    }
    for (int i=1; i<=n; i++)
    {
        if (!vis[i]) dfs(i);
    }
    for (int i=1; i<=n; i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}

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

using namespace std;
int n,u,k;

class points{
    public:
    int flag=0;
    list<int> l;
    int d=0;
    int f=0;
}pt[110];
int tem;

int times=0;

void dfa(int cur){
    times+=1;
    pt[cur].d=times;
    pt[cur].flag=1;
    while(!pt[cur].l.empty()){
        int dst=pt[cur].l.front();
            if(pt[dst].flag==0){
                dfa(dst);
            }
        pt[cur].l.pop_front();
    }
    times+=1;
    pt[cur].f=times;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>tem;
            pt[u].l.push_back(tem);
        }
    }
    for(int i=1;i<=n;i++){
        if(pt[i].flag==0){
            dfa(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<pt[i].d<<" "<<pt[i].f<<endl;
    }
    
}