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
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			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
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	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;
const int MAXn=100;

int n,M[MAXn][MAXn]={0},nt[MAXn],col[MAXn];//color:0=white,1=gray,2=brack
int d[MAXn],f[MAXn],t;

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 u)
{
	stack<int> S;
	S.push(u);
	col[u]=1;
	d[u]=++t;
	while(!S.empty())
	{
		int v=S.top();
		int r=next(v);
		if(r!=-1)
		{
			if(col[r]==0)
			{
				col[r]=1;
				d[r]=++t;
				S.push(r);
			}
		}
		else
		{
			S.pop();
			col[v]=2;
			f[v]=++t;
		}
	}
	return;
}

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

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

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

using namespace std;
int graph[125][125], color[125], times, s[125], f[125], v, w, n;
class DFS{
public:
	static void search(){
		for(int i = 1;i<=n;i++){
			color[i] = 0;
		}
		times = 0;
		for(int u = 1;u<=n;u++){
			if(color[u] == 0){
				visit(u);
			}
		}
	}
	static void visit(int u){
		color[u] = 1;
		s[u] = ++times;
		for(int w=1;w<=n;w++){
			if(graph[u][w] == 0) continue;
			if(color[w] == 0){
				visit(w);
			}
		}
		color[u] = 2;
		f[u] = ++times;
	}
};
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			graph[i][j] = 0;
		}
	}

	for(int i=1;i<=n;i++){
		int num;
		int k;
		int tmp;
		cin >> num >> k;
		if(k !=0){
			for(int j=0;j<k;j++){
				cin >> tmp;
				graph[num][tmp] = 1;
			}
		}
	}
	DFS::search();
	int i;
	for(i=1;i<=n;i++){
		cout << i << " " << s[i] << " " << f[i] << endl;
	}
}

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

using namespace std;

int main(){
    stack<int> st;
    int n;
    cin >> n;
    int d[n] = {};
    int f[n] = {};
    int vnum[n][2] = {};
    bool vflag[n] = {};
    int tmp2;
    int num;
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        vnum[i][0] = num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    int cnt = 1;
    bool check;
    int s;
    st.push(0);
    do{
        s = st.top();

        if(((vnum[s][0]==0) && d[s]==0) || (s==vertex[s][vnum[s][1]]-1)){
            vflag[s] = true;
            d[s] = cnt++;
            f[s] = cnt++;
            st.pop();
        }else if(vnum[s][0]==vnum[s][1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if((vflag[vertex[s][vnum[s][1]]-1]) && (d[s]==0)){
            if(vnum[s][0]-vnum[s][1]==1){
                vflag[s] = true;
                d[s] = cnt++;
                f[s] = cnt++;
                st.pop();
            }else{
                vnum[s][1]++;
            }
        }else if(vflag[vertex[s][vnum[s][1]]-1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if(vflag[s]){
            st.push(vertex[s][vnum[s][1]++] - 1);
        }else{
            if(d[s]==0){
                d[s] = cnt++;
            }
            st.push(vertex[s][vnum[s][1]++] - 1);
            if(vnum[s][0]==vnum[s][1]){
                vflag[s] = true;
            }
            if(vflag[vertex[s][vnum[s][1]]-1]){
                f[s] = cnt++;
                st.pop();
            }
        }
        check = !st.empty();
        if(!check){
            for(int i=0;i<n;i++){
                if(vflag[i]==false){
                    check = true;
                    st.push(i);
                    break;
                }
            }
        }
    }while(check);

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

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

int n;
int M[100][100];
int color[100], d[100], f[100];
int t;

void Dfs(int u) {
  color[u] = 1;
  d[u] = ++t;
  for (int v = 0; v < n; v++) if (M[u][v] && color[v] == 0) Dfs(v);
  color[u] = 2;
  f[u] = ++t;
}

int main() {
  cin >> n;

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

  Dfs(0);

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

  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	stack<int> s;
	int count=1;
	s.push(0);
	a[0]=1;
	while(s.empty()==0){
		count++;
		int x=s.top();
		rep(i,k[x]){
			if(a[v[x][i]]==0){
				s.push(v[x][i]);
				a[v[x][i]]=count;
				break;
			}
			if(i==k[x]-1){
				k[x]=0;
			}
		}
		if(k[x]==0){
				b[x]=count;
				s.pop();
		}
		if(s.empty()==1){
			rep(i,n){
				if(a[i]==0){
					s.push(i);
					count++;
					a[i]=count;
				}
			}
		}
	}

	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;;
	}

		



	return 0;
}