Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

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