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;

struct Vertex
{
    int id, k, *adjcent, start, end;
    bool passed = false;
};

Vertex *vertexs;
int time_ = 0;

void DFS(int now)
{
    vertexs[now].passed = true;
    time_++;
    vertexs[now].start = time_;
    for(int i=0; i<vertexs[now].k; i++)
    {
        if(!vertexs[vertexs[now].adjcent[i]].passed) DFS(vertexs[now].adjcent[i]);
    }
    time_++;
    vertexs[now].end = time_;
}

int main()
{
    int n;
    scanf("%d", &n);
    vertexs = new Vertex[n+1];
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &vertexs[i].id, &vertexs[i].k);
        vertexs[i].adjcent = new int[vertexs[i].k];
        for(int j=0; j<vertexs[i].k; j++)
        {
            scanf("%d", &vertexs[i].adjcent[j]);
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(!vertexs[i].passed) DFS(vertexs[i].id);
    }
    for(int i=1; i<=n; i++) printf("%d %d %d\n", vertexs[i].id, vertexs[i].start, vertexs[i].end);

    return 0;
}

C++: #include <iostream>
#define N 110

int t = 1;

int d[N], f[N];
int A[N][N];

void Depth(int id, int n){
  d[id] = t;
  t++;
  for(int i=1; i<=n; i++){
    if(A[id][i] == 1 && d[i] == 0){
      Depth(i, n);
    }
  }
  f[id] = t;
  t++;
}



int main(){
  for(int i=0; i<N; i++){
    d[i]=f[i]=0;
    for(int j=0; j<N; j++){
      A[i][j]=0;
    }
  }
  int n;
  std::cin >> n;
  for(int i=0; i<n; i++){
    int u, k, v;
    std::cin >> u >> k;
    for(int i=0; i<k; i++){
      std::cin >> v;
      A[u][v]=1;
    }
  }
  for(int i=1; i<=n; i++){
    if(d[i] == 0 && f[i] == 0){ Depth(i, n); }
  }
  for(int i=1; i<=n; i++){
    std::cout << i << " " << d[i] << " " << f[i] << std::endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

vector<int> G[110];

int timer;
int d[110],f[110];

bool used[110];

void dfs(int x)
{
    used[x]=true;
    d[x]=++timer;

    for(int i=0;i<G[x].size();i++)
    {
        if(!used[G[x][i]])
        {
            dfs(G[x][i]);
        }
    }

    f[x]=++timer;
}


int main()
{

    int n;

    cin>>n;

    for(int i=0;i<n;i++)
    {
        int a,b,c;

        cin>>a>>b;

        for(int i=0;i<b;i++)
        {
            cin>>c;

            G[a].push_back(c);
        }
    }

    timer=0;
    memset(used,0,sizeof(used));

    for(int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            dfs(i);
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <stack>
#define MAX 101
#define NIL -1

using namespace std;


int matrix[MAX][MAX] = {0};
int d[MAX], f[MAX];
int n, t;

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

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> v;
			matrix[u][v] = 1;			
		}
	}
	
//显示邻接矩阵 
//	for (int i = 0; i < n; i++)
//	{
//		for (int j = 0; j < n; j++)
//		{
//			if(j) cout << ' ';
//			cout << matrix[i+1][j+1];		
//		}
//		cout << endl;
//	}
	
	
	dfs();
	
	
	for (int i = 1; i <= n; i++)
	{
		cout << i << ' ';
		cout << d[i] << ' ';	
		cout << f[i] << endl;
	}
} 



void dfs()
{	
	for (int i = 1; i <= n; i++)
	{
		if (d[i] == 0)
			dfs_visit(i);
	}
}



void dfs_visit(int u)
{

	stack<int> S;
	S.push(u);
	d[u] = ++t;
	
	while (!S.empty())
	{
		u = next(S.top());
		if (u)
		{
//			if (d[u] == 0)
			{
			d[u] = ++t;
			S.push(u); 				
			}
		}
		else
		{
			f[S.top()] = ++t;
			S.pop();
		}
		
	}
	
}


int next(int u)
{
	for (int i = 1; i <= n; i++)
	{
		if (matrix[u][i] != 0 && d[i] == 0)
			return i;
	}
	return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>

struct TNode
{
	int Index;
	bool Visited;
	std::list<TNode*> Target;
	
	int ClockStart;
	int ClockEnd;
	
	TNode(int AIndex)
	: Index(AIndex), Visited(false), ClockStart(0), ClockEnd(0)
	{
	}
	
	void Visit(int& Clock)
	{
		if(Visited) return;
		Visited = true;
		ClockStart = Clock;
		++Clock;
		for(std::list<TNode*>::iterator It = Target.begin(); It != Target.end(); ++It){
			(*It)->Visit(Clock);
		}
		ClockEnd = Clock;
		++Clock;
	}
};

class TGraph
{
	std::vector<TNode*> FNodes;
public:
	TGraph(int Count)
	: FNodes(Count)
	{
		for(int i = 0; i < Count; ++i){
			FNodes[i] = new TNode(i + 1);
		}
	}
	
	~TGraph()
	{
		for(unsigned int i = 0; i < FNodes.size(); ++i){
			delete FNodes[i];
		}
	}
	
	void InputNode(int Index, int BranchCount)
	{
		for(int i = 0; i < BranchCount; ++i){
			int Target;
			std::cin >> Target;
			FNodes[Index - 1]->Target.push_back(FNodes[Target - 1]);
		}
	}
	
	void DepthFirstSearch()
	{
		int Clock = 1;
		for(unsigned int i = 0; i < FNodes.size(); ++i){
			FNodes[i]->Visit(Clock);
		}
	}
	
	void OutputClocks()const
	{
		for(unsigned int i = 0; i < FNodes.size(); ++i){
			std::cout << FNodes[i]->Index      << " "
			          << FNodes[i]->ClockStart << " "
			          << FNodes[i]->ClockEnd   << std::endl;
		}
	}
};

int main()
{
	int Count;
	std::cin >> Count;
	TGraph Graph(Count);
	for(int i = 0; i < Count; ++i){
		int Index;
		std::cin >> Index;
		int BranchCount;
		std::cin >> BranchCount;
		Graph.InputNode(Index, BranchCount);
	}
	Graph.DepthFirstSearch();
	Graph.OutputClocks();
	return 0;
}