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

struct Node{
    bool comp;
    int starttime, endtime;
};

int Time = 1;

void setTime(queue<int> q[], stack<int> t, Node l[]){
    if(Time == 1){
        t.push(1);
        l[0].starttime = Time++;
        setTime(q, t, l);
    }

    if(t.size() == 0){
        return;
    }

    int index = t.top() -1;

    // if(l[index].comp){
    //     cout << index << endl;
    //     t.pop();
    //     setTime(q, t, l);
    // }

    if(q[index].size() == 0){
        t.pop();
        l[index].endtime = Time++;
        l[index].comp = true;
        setTime(q, t, l);
    } else {
        int val = q[index].front();
        q[index].pop();

        if(l[val - 1].comp) setTime(q, t, l);
        else{
            t.push(val);
            l[val - 1].starttime = Time++;
            setTime(q, t, l);
        }
    }

}

int main(){
    int n, v, k, l;
    cin >> n;
    queue<int> q[n];
    stack<int > timetable;
    Node timelist[n];
    for(int i=0; i<n; i++){
        cin >> v >> k;
        v--;
        timelist[i].comp = false;
        for(int j=0; j<k; j++){
            cin >> l;
            q[v].push(l);
        }
    }

    setTime(q, timetable, timelist);

    for(int i=0; i<n; i++){
        cout << i+1 << " " << timelist[i].starttime << " " << timelist[i].endtime << endl;
    }

    return 0;

}

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() {
	scanf("%d", &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 <iostream>
#include <utility>
#include <vector>
using namespace std;

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int> > G[101];

int ti = 1;

void dfs(int id) {
	if (d[id]) return ;
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0; i<(int)adj.size(); ++i) {
		dfs(adj[i]);
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	for (int i=1; i<=n; ++i) {
		dfs(i);
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
int a[N][N];
int t = 0;
int color[N], check[N], finish[N];
void dfs(int u) {
  t++;
  check[u] = t;
  color[u] = GRAY;
  for (int i = 0; i < n; i++) {
    if (a[u][i] == 0) continue;
    if (color[i] == WHITE) {
      dfs(i);
    }
  }
  color[u] = BLACK;
  finish[u] = ++t;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) a[i][j] = 0;
  }

  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--;
      a[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
  }
  for (int i = 0; i < n; i++) {
    if (color[i] == WHITE) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << check[i] << " " << finish[i] << endl;
  }
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

//??¶????????°
int n;
//?????\??????
int M[N][N];
//??°?????¶???????¢????
int color[N];
//??\??¶????????°??¶???
int d[N];
//??\??¶???????????¶???
int f[N];
//??¶???
int tt;
//???????????????????????????????????????
//?????¨?????????????????¨????????\??????????????????
int nt[N];

//????????????????????????u?????????v
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&&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++)
        nt[i]=0,color[i]=WHITE;
    tt=0;

    //??\????????????u?????????????????±?????????????´¢
    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,k,v;

    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;

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

    dfs();
}