Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
vector<int> d, f;
vector<vector<int>> g;
void dfs(int now, int &time) {
    d[now] = time;
    time++;
    for (int nxt : g[now]) {
        if (d[nxt] != -1) continue;
        dfs(nxt, time);
    }
    f[now] = time;
    time++;
}
int main() {
    int n;
    cin >> n;
    g.resize(n);
    d.assign(n, -1);
    f.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            g[i].push_back(v);
        }
    }
    int time = 1;
    rep(i,n) {
        if(d[i]==-1) dfs(i,time);
    }
    rep(i,n) {
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

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