Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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