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 <vector>
#include <stack>

using namespace std;
const int INF = 1001001001;

void step1(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int node, int& time)
{
    // stackを使用
    stack<int> S;
    S.push(node);
    d[node] = ++time;
    color[node] = 1;
    while(!S.empty())
    {
        node = S.top();
        if(color[node] != 2){
            bool flag = true;
            for(int e : edges[node])
            {
                if(color[e] == 0)
                {
                    S.push(e);
                    d[e] = ++time;
                    color[e] = 1;
                    flag = false;
                    break;
                }
            }
            if(flag) color[node] = 2;
        }
        else
        {
            f[node] = ++time;
            S.pop();
        }
    }
}

void step2(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int node, int& time)
{
    d[node] = ++time;
    color[node] = 1;
    for(int e : edges[node])
        {
            if(color[e] == 0) step2(edges, d, f, color, e, time);
        }
    
    f[node] = ++time;
}

void dfs(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int n)
{
    int time=0;
    for(int i=0;i<n;++i)
    {
        if(color[i] == 0) step2(edges, d, f, color, i, time);
    }
}

int main()
{
    int n, u, k, e;
    cin >> n;
    vector< vector<int> > edges(n);
    vector<int> d(n), f(n), color(n);
    for(int i=0;i<n;++i)
    {
        //d[i] = f[i] = INF;
    }
    for(int i=0;i<n;++i)
    {
        cin >> u >> k;
        --u;
        for(int j=0;j<k;++j)
        {
            cin >> e;
            --e;
            edges[u].push_back(e);
            //edges[e].push_back(u);
        }
    }

    dfs(edges, d, f, color, n);
    for(int i = 0;i < n; ++i)
    {
        cout << i+1 << " " << d[i] << " " << f[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;





//用栈实现深度优先搜索


/**
 * color 标记访问状态的数组，
 * M[N][N] 邻接矩阵 如果存在定点i到顶点j的边，则M[i][j]=trul
 * Stack 栈，暂存访问过程中的顶点
**/
int n,M[N][N];
int color[N],d[N],f[N],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(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(u);
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return;
}
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 i=0;i<k;i++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }

    dfs();
    return 0;
}

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

template<typename T>
T gcd(T a, T b)
{
	return b ? gcd(b, a%b) : a;
}

template<typename T>
T lcm(T a, T b)
{
	return a / gcd(a, b) * b;
}

//(a^e)%mod
template<typename T>
T power(T a, T e, T mod)
{
	if(e == 0)
	{
		return 1;
	}
	if(e % 2 != 0)
	{
		//a^e=a^(e-1)*a
		return (power(a, e - 1, mod) * a) % mod;
	}
	T res = power(a, e / 2, mod);
	//a^e=a^(e/2)*a^(e/2)
	return (res * res) % mod;
}

template<typename T>
class Tree
{
private:
public:
	T data;
	Tree* parent = NULL;
	std::vector<Tree*> children;
	void setData(T x)
	{
		data = x;
	}
	void setParent(Tree* t)
	{
		parent = t;
	}
	void addChild(Tree* t)
	{
		children.push_back(t);
	}
	Tree(){}
	~Tree(){}
	
};

template<typename T>
class Graph
{
public:
	T index;
	vector<T> edge;
	void setEdge(T t)
	{
		edge.push_back(t);
	}
	Graph(){}
	~Graph(){}
};

Graph<int> G[101];
pair<int, int> timeStamp[101] = {};
int cn = 1;

void rec(int now)
{
	if(timeStamp[now].first != 0)
	{
		return;
	}
	timeStamp[now].first = cn++;
	for (auto t : G[now].edge)
	{
		rec(t);
	}
	timeStamp[now].second = cn++;
}

int main()
{
	using namespace std;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int index, k;
		cin >> index >> k;
		G[index].index = index;
		for (int j = 0; j < k; ++j)
		{
			int in;
			cin >> in;
			G[index].setEdge(in);
		}
		sort(G[index].edge.begin(), G[index].edge.end());
	}
	for (int i = 1; i <= n; ++i)
	{
		rec(i);
	}
	for (int i = 1; i <= n; ++i)
	{
		cout << i <<" " << timeStamp[i].first << " " << timeStamp[i].second << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;
int v[105],d[105],f[105],m[105][105];
int tt,n;
void dfs(int u)
{
    d[u]=++tt;
    v[u]=true;
    for(int i=0;i<n;i++)
        if(m[u][i]&&!v[i])dfs(i);
    f[u]=++tt;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,v,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)cin>>v,m[u-1][v-1]=true;
    }
    for(int i=0;i<n;i++)if(!v[i])dfs(i);
    for(int i=0;i<n;i++)cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
    return 0;
}

C++: n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
G = [0 for i in range(n)]
 
 
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
     
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
 
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        a[G[0]-1][G[2+j]-1] = 1