Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <stack>
#include <map>

using namespace std;

template<typename ISTREAM>
void readGraphListAsMatrix(const size_t n, ISTREAM& cin, vector< vector<int> >& graphMatrix) {
	graphMatrix = vector< vector<int> >(n, vector<int>(n, 0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u;
		cin>> k;
		for (size_t j = 0; j != k; ++j) {
			size_t v;
			cin >> v;
			graphMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
}

void printMatrix(const vector< vector<int> >& grapthMatrix) {
	const size_t n = grapthMatrix.size();
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}
}


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > graphMatrix;
	readGraphListAsMatrix(n, cin, graphMatrix);
	stack<int> visitedNodeIDs;
	visitedNodeIDs.push(0);
	int time = 0;
	vector<pair<int, int>> timeStamp(n,make_pair(0,0));//pair<初回訪問時刻, 完了時刻>
	vector<vector<int>::iterator> searchBeginPos; {
		searchBeginPos.reserve(n);
		for (auto& v : graphMatrix)searchBeginPos.push_back(v.begin());
	}
	timeStamp.at(0).first = 1;
	while (!visitedNodeIDs.empty()) {
		++time;
		const int nodeID_1 = visitedNodeIDs.top();
		vector<int>& neighbourNodeList = graphMatrix.at(nodeID_1);
		vector<int>::iterator result = find(searchBeginPos.at(nodeID_1), neighbourNodeList.end(), 1);
		if (result != neighbourNodeList.end()) {
			const int nextVisitID_1 = distance(neighbourNodeList.begin(), result);
			timeStamp.at(nextVisitID_1).first = time + 1;
			for (auto&v : graphMatrix) v.at(nextVisitID_1) = 0;
			visitedNodeIDs.push(nextVisitID_1);
			searchBeginPos.at(nodeID_1) = result + 1;
		}
		else {
			//隣接リストに検索対象なし
			timeStamp.at(nodeID_1).second = time+1;
			visitedNodeIDs.pop();
		}
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << timeStamp.at(i).first << " " << timeStamp.at(i).second << endl;
	}
}

int main()
{
	execute(cin);

	return 0;
}

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

int d[101]={0};
int f[101]={0};
int AdjM[101][101]={0};
int lapse=0;

void dfs(int cur){
    ++lapse;
    d[cur]=lapse;
    //cerr<<"visiting "<<cur<<" "<<lapse<<"\n";
    for(int dst=1;dst<101;++dst){
        if(AdjM[cur][dst]!=0 && d[dst]==0){
            dfs(dst);
        }
    }
    ++lapse;
    f[cur]=lapse;
}

int main(){
    int N;
    cin>>N;
    int id,edgnum,adj;
    for(int i=0;i<N;++i){
        cin>>id>>edgnum;
        for(int j=0;j<edgnum;++j){
            cin>>adj;
            AdjM[id][adj]+=1;
        }
    }

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

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

C++: #include <iostream>
#include <stack>
#define NUM 100
using namespace std;
int process_time;

typedef enum
{
    PRE,
    NOW,
} NodeStatus;

struct Node
{
    int num;
    int *p;
    int d;
    int f;

    int status;
    void Set(int num);
};

void Node::Set(int n)
{
    this->num = n;
    this->status = PRE;
    p = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
}

void Search(Node *vertex, int start)
{
    stack<Node *> st;

    st.push(&vertex[start]);
    vertex[start].status = NOW;
    vertex[start].d = process_time;
    while (!st.empty())
    {
        process_time++;
        int k = st.top()->num;
        int i;
        for (i = 0; i < k; i++)
        {
            if (vertex[st.top()->p[i]].status == PRE)
            {
                break;
            }
        }
        if (i == k)
        {
            Node *v;
            v = st.top();
            st.pop();
            v->f = process_time;
        }
        else
        {
            st.push(&vertex[st.top()->p[i]]);
            st.top()->d = process_time;
            st.top()->status = NOW;
        }
    }
}

int main()
{
    int n;
    Node vertex[NUM];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        int k, u;
        cin >> u >> k;
        vertex[u].Set(k);
    }

    process_time = 1;
    Search(vertex, 1);

    int count;
    for (count = 1; count <= n; count++)
    {
        if (vertex[count].status == PRE)
        {
            break;
        }
    }
    if (count != n + 1)
    {
        process_time++;
        Search(vertex, count);
    }

    for (int i = 1; i <= n; i++)
    {
        cout << i << ' ' << vertex[i].d << ' ' << vertex[i].f << endl;
    }
    /*for (int i = 1; i <= n; i++) //1オリジン
    {
        for (int j = 0; j < vertex[i].num; j++)
        {
            cout << vertex[i].p[j] << ' ';
        }
        cout << endl;
    }*/

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
int t=1;
v<int> d,f;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
  if(seen[v]==true) return;
  seen[v] = true; // v を訪問済にする
  d[v]=t++;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    dfs(G, next_v); // 再帰的に探索
  }
  f[v]=t++;
}

signed _main() {
  // 頂点数と辺数
  int N; cin >> N;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  d.resize(N);
  f.resize(N);
  for (int i = 0; i < N; ++i) {
    int u, k; cin >> u >> k;
    u--;
    rep(j,k){
      int v; cin >> v;
      v--;
      G[u].push_back(v);
    }
  }

  // 頂点 0 をスタートとした探索
  seen.assign(N, false); // 全頂点を「未訪問」に初期化
  rep(i,N){
    dfs(G,i);
  }
  rep(i,N){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#define N 100
#define  GRAY 1
#define BLACK 2
using namespace std;
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0;v<n;v++)
  {  if(M[u][v] == 0)
     continue;
  if(color[v] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) dfs_visit(u);
  }
  for(u = 0;u<n;u++)
  {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&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++)
   {
     scanf("%d %d",&n,&k);
     u--;
     for(int j = 0;j<n;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}