Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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();
}