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

	vector<pair<int, int>>::iterator visitTimeSearchPos = timeStamp.begin();
	while (
		(visitTimeSearchPos = find_if(visitTimeSearchPos, timeStamp.end(), [&](const pair<int, int>& df) {return df.first == 0; }))
		!= timeStamp.end()) {
		const size_t firstVisitNodeID_1 = distance(timeStamp.begin(), visitTimeSearchPos);
		visitedNodeIDs.push(firstVisitNodeID_1);
		visitTimeSearchPos->first = ++time;
		for (auto&v : graphMatrix) v.at(firstVisitNodeID_1) = 0;
		++visitTimeSearchPos;
		while (!visitedNodeIDs.empty()) {
			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();
			}
			++time;
		}
	}
	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 <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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] == WHITE)
    {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs()
{
  int u;
  // 初期化
  for (u = 0; u < n; u++)
    color[u] = WHITE;
  tt = 0;

  for (u = 0; u < n; u++)
  {
    // 未訪問のuを始点として深さ優先探索
    if (color[u] == WHITE)
      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", &u, &k);
    u--;
    for (j = 0; j < k; j++)
    {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

const int N = 100;
int n;
int d[N+1], f[N+1], state[N+1], ns[N+1][N+1];
stack<int> s;

int next(int u) {
  FOR(i, 1, n+1) {
    if (ns[u][i] == 1 && state[i] == 0) return i;
  }
  return -1;
}
int main() {
	cin.tie(0);
 	ios::sync_with_stdio(false);

  cin >> n;

  FOR(i, 1, n+1) state[i] = 0;
  FOR(i, 1, n+1) {
    FOR(j, 1, n+1) {
      ns[i][j] = 0;
    }
  }

  REP(i, n) {
    int p, m;
    cin >> p; cin >> m;

    REP(j, m) {
      int pp; cin >> pp;
      ns[p][pp] = 1;
    }
  }

  int t = 1;

  s.push(1);
  state[1] = 1;
  d[1] = 1;
  while (!s.empty()) {
    t++;

    int p, np;
    p = s.top();
    if ((np = next(p)) != -1) {
      s.push(np);
      state[np] = 1;
      d[np] = t;
    } else {
      s.pop();
      state[p] = 2;
      f[p] = t;
    }
  }

  FOR(i, 1, n+1) {
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
}

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

#define N 101

void DepthFirstSearch();

class stack{
public:
    int array[100];
    int top = -1;
    
    void push(int v) {
        top++;
        array[top] = v;
        return;
    }
    
    int pop() {
        top--;
        return array[top+1];
    }
    
    int show() {
        return array[top];
    }
};

typedef struct {
    int d;
    int f;
} P;

int n;
int t = 0;
int a[N][N] = {};
stack s;
P list[N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    
    int u, k, v;
    for(int i = 0; i < n; i++) {
        cin>>u>>k;
        
        for(int j = 0; j < k; j++) {
            cin>>v;
            a[u][v] = 1;
        }
    }
    
    for(int i = 1; i <= n; i++) {
        if(list[i].d == 0) {
            s.push(i);
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    
    for(int i = 1; i <= n; i++) {
        cout<<i<<' '<<list[i].d<<' '<<list[i].f<<endl;
    }
    
    return 0;
}

void DepthFirstSearch() {
    t++;
    int u = s.show();
    list[u].d = t;
    for(int i = 1; i <= n; i++) {
        if( a[u][i] == 1 ) {
            s.push(i);
            a[u][i] = 0;
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    t++;
    list[u].f = t;
}