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>
#include<stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

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();
        //cout << "s.top=" << u << endl;
        int v=next(u);
        //cout << "u.next=" << v << endl;
        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 i=0;i<n;i++)
    {
        color[i]=WHITE;
        nt[i]=0;
    }


    tt=0;

    for(int u=0;u<n;u++)
    {
        if(color[u]==WHITE)
        {
            //cout << "visit " << u << endl;
            dfs_visit(u);
        }
    }

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

int main()
{
    int u,k,v,node;
    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;//row
        if(i==u-1)
        {
            cin >> node;//number of node
            for(int j=0;j<node;j++)
            {
                cin >> v;
                M[i][v-1]=1;
            }
        }
    }

    /*
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout << M[i][j] << " " ;
        }
        cout << endl;
    }*/

    dfs();
    return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

struct GraphParser {
  GraphParser(vector<vector<int>>& edges_)
      : edges(edges_), start(edges.size(), 0), end(edges.size(), 0) {
    //
  }

  void run() {
    t = 0;
    for (size_t i = 0; i < edges.size(); ++i) {
      if (!start[i]) {
        recur(i);
      }
    }
  }

  vector<vector<int>>& edges;
  vector<int> start;
  vector<int> end;
  int t;

 private:
  void recur(int cur) {
    if (start[cur]) {
      return;
    }
    start[cur] = ++t;
    for (auto&& e : edges[cur]) {
      recur(e);
    }
    end[cur] = ++t;
  }
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> edges(n, vector<int>());
  for (int i = 0; i < n; ++i) {
    int u;
    int k;
    cin >> u >> k;
    edges[u - 1].reserve(k);
    for (int j = 0; j < k; ++j) {
      int v;
      cin >> v;
      edges[u - 1].push_back(v - 1);
    }
  }

  GraphParser p(edges);
  p.run();
  for (int i = 0; i < n; ++i) {
    cout << (i + 1) << " " << p.start[i] << " " << p.end[i] << endl;
  }
}

C++: // 2015/01/05 Tazoe

#include <iostream>
#include <stack>
using namespace std;

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

	int G[100][100] = {0};

	for(int i=0; i<n; i++){
		int u, k;
		cin >> u >> k;

		for(int j=0; j<k; j++){
			int v;
			cin >> v;

			G[u-1][v-1] = 1;
		}
	}

//	for(int i=0; i<n; i++){
//		for(int j=0; j<n; j++){
//			cout << G[i][j] << ' ';
//		}
//		cout << endl;
//	}

	int d[100] = {0};
	int f[100] = {0};

	stack<int> S;
	int T = 0;

	S.push(0);
	d[0] = ++T;

	while(!S.empty()){
		int u = S.top();

		int v = -1;
		for(int j=0; j<n; j++){
			if(G[u][j]==1 && d[j]==0){
				v = j;
				break;
			}
		}

		if(v!=-1){
			S.push(v);
			d[v] = ++T;
		}
		else{
			S.pop();
			f[u] = ++T;
		}
	}

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

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

void get_network(int N,vector<vector<int>>& array){
    int u,k,x;

    for(int i=0;i<N;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>x;
            array[u-1][x-1]=1;
        }
    }

}

int dfs_rec(vector<int>& flag,int n,vector<vector<int>>& A,int v,vector<int>& f,vector<int>& d,int t){
        flag[v]=1;
        d[v]=t;
        for(int i=0;i<n;i++){
                if(A[v][i]==1 && flag[i]!=1){
                        t=dfs_rec(flag,n,A,i,f,d,t+1);

                }
        }
        f[v]=t+1;
        t++;
        return t;
}


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

        int n;
        cin>>n;
        vector<vector<int>> array(n,vector<int>(n,0));
        get_network(n,array);

        //
        vector<int> flag(n,-1);
        vector<int> d(n,0);
        vector<int> f(n,0);
        //
        int t=0;
        t=dfs_rec(flag,n,array,0,f,d,t);
        for(int i=0;i<n;i++){
                if(flag[i]==-1){
                        t=dfs_rec(flag,n,array,i,f,d,t+1);
                }
        }
        //

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

        return 0;
}

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,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u);
void dfs_visit(int r);
void dfs();

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

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 i=0;i<n;i++){
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;
	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;
	}
}