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<cstdio>
#include<stack>
#include<algorithm>
#include<cstring>
#define white 0
#define balck -1
#define grey 1
using namespace std;

int a[110][110],n;
int color[110];
int t=0;
int ts[105],te[105];

void dfsinit()
{
    for(int i=1;i<=100;i++)
        color[i]=white;
}

void dfsvisit(int u)
{
    color[u]=grey;
    ts[u]=++t;  //搜索
    for(int j=1;j<=n;j++)  //搜索?点
    {
        if(color[j]==white && a[u][j]==1)
        {
           dfsvisit(j);  //深搜
        }
    }
    te[u]=++t;
    color[u]=balck;
}

void dfs()
{
    dfsinit();
    for(int i=1;i<=n;i++)
    {
        if(color[i]==white)
            dfsvisit(i);
    }
}

int main()
{
   int key,d,x;
   t=0;
   memset(a,0,sizeof(a));
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       scanf("%d%d",&key,&d);
       for(int j=1;j<=d;j++)
       {
        scanf("%d",&x);
        a[key][x]=1;
       }
   }

   dfs();
   for(int i=1;i<=n;i++)
   {
       printf("%d %d %d\n",i,ts[i],te[i]);
   }
   return 0;
}

C++: #include<iostream>
#include<vector>
#include<stack>
#include<climits>

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
 unsigned long checkedNodeNum;

 void stampStart(unsigned long time){
  timestampStart = time;
 };

 void stampFinish(unsigned long time){
  timestampFinish = time;
 };
 

public:
 Node(unsigned long nodeId = 0, unsigned long adjectNodenum = 0)
                  : nodeId(nodeId),
                    timestampStart(0),
                    timestampFinish(0),
                    adjectNode(vector<unsigned long>(adjectNodenum, 0)),
                    checkedNodeNum(0){

 for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodenum; ++adjectNode_i){
  unsigned long adjectNodeId = 0; cin >> adjectNodeId;

  adjectNode[adjectNode_i] = adjectNodeId;
 } 

 };

 unsigned long getNotCheckedAdjectNode(unsigned long time){
  unsigned long AdjectNodeMax = adjectNode.size();
  if(checkedNodeNum == 0){
   stampStart(time);
  }else if(checkedNodeNum >= AdjectNodeMax){
   stampFinish(time);
   return ULONG_MAX;
  }


  ++checkedNodeNum;

  if(AdjectNodeMax == 0){
   return nodeId;
  }

  return adjectNode[checkedNodeNum-1];

 };

 bool isChecked(){
  if(timestampStart != 0) return true;
  return false;
 }

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };


protected:
};

class Graph{
private:
 vector<Node*> graph;

public:
 Graph(unsigned long nodeNum = 0)
                  : graph(vector<Node*>(nodeNum, 0)){
  for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
   unsigned long nodeId = 0; cin >> nodeId;
   unsigned long adjectNodenum = 0; cin >> adjectNodenum;
   Node* temp_node = new Node(nodeId, adjectNodenum);
   graph[nodeId-1] = temp_node;
  }
 };

 void DepthFirstSearch(){
  unsigned long time = 1;
  stack<unsigned long> checkedNode;
  if(graph[0] == 0) return ;

  checkedNode.push(1);
  while(!checkedNode.empty()){
   unsigned long nowNode = checkedNode.top();
   if(unsigned long nextNode = graph[nowNode-1]->getNotCheckedAdjectNode(time)){
    if(nextNode == ULONG_MAX){
     checkedNode.pop();
    }else if(nextNode == nowNode){
    }else if(graph[nextNode-1]->isChecked()){
     continue;
    }else{
     checkedNode.push(nextNode);
    }
   }
   ++time;
  }

 };

 void display(){
  for(unsigned long node_i = 0, nodeNum = graph.size(); node_i < nodeNum; ++node_i){
   graph[node_i]->display();
  }
 };

protected:

};

int main(){
 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

C++: // ALDS1_11_B
#include <iostream>
#include <vector>
using namespace std;

void DFS(vector<vector<int> > A, vector<int> &d, vector<int> &f, vector<int> &visit, int &t, int v){
	
	visit[v] = 1;
	d[v] = t++;

	for(int i=0;i<A[v].size();i++)
		if((A[v][i] == 1) && (visit[i] == 0))
			DFS(A, d, f, visit, t, i);

	f[v] = t++;
}

int main(){
	int n, u, k, t=1;
	vector<vector<int> > A;
	vector<int> d, f, visit;

	cin>>n;
	A.resize(n);
	d.resize(n);
	f.resize(n);
	for(int i=0;i<n;i++){
		A[i].resize(n);
		visit.push_back(0);
	}

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			A[i][j] = 0;

	for(int i=0;i<n;i++){
		cin>>u>>k;
		int v;
		
		for(int j=0;j<k;j++){
			cin>>v;
			A[u-1][v-1] = 1;
		}
	}

	for(int i=0;i<n;i++)
		if(!visit[i])
			DFS(A, d, f, visit, t, i);
	
	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;

	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

const int MAX_N = 100;
int s[MAX_N + 1], e[MAX_N + 1];
int N, t = 1;
vector<vector<int>> g(MAX_N + 1);

void dfs(int i) {
  if (s[i] > 0) return;
  // cout << "i = " << i << ", t = " << t << endl;

  s[i] = t++;
  for (int j = 0; j < g[i].size(); j++) {
    dfs(g[i][j]);
  }
  e[i] = t++;
}

void dfs() {
  for (int i = 1; i <= N; i++) {
    if (s[i] > 0) continue;
    dfs(i);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  cin >> N;
  for (int i = 0; i < N; i++) {
    int u; cin >> u;
    int k; cin >> k;
    for (int ki = 0; ki < k; ki++) {
      int tmp; cin >> tmp;
      g[u].push_back(tmp);
    }
    sort(g[u])
  }

  memset(s, 0, sizeof(s));
  memset(e, 0, sizeof(e));

  // outl("-------------")
  // for (int i = 1; i <= N; i++) {
  //   cout << i << " ";
  //   for (int j = 0; j < g[i].size(); j++) {
  //     cout << g[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  // outl("-------------")

  dfs();

  for (int i = 1; i <= N; i++) {
    cout << i << " " << s[i] << " " << e[i] << endl;
  }
}