Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define NIL -1

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

bool adj[105][105];
bool vis[105];
struct node{
	int ft;
	int rt;
};
node v[105];

int n;
int cnt;

void dfs (int cur )
{
	cnt++;
	vis[cur] = true;	
	v[cur].ft = cnt;
	for (int u = 1; u <= n; u++ ){
		if (!vis[u] && adj[cur][u] )
			dfs (u );
	} // end for
	cnt++;
	v[cur].rt = cnt;
}

int main()
{
	memset (adj, false, sizeof (adj ) );
	memset (vis, false, sizeof (vis ) );

	ios_base::sync_with_stdio(0);
	cin >> n;

	rep (i, n ) v[i].ft = NIL, v[i].rt = NIL;

	rep (i, n ){
		int v, k;
		cin >> v >> k;
		while (k-- ){
			int u; cin >> u;
			adj[v][u] = true;
		} // end rep
	} // end rep
	cnt = 0;
	while (true ){
		bool ok = true;
		for (int i = 1; i <= n; i++ ){
			if (v[i].ft == NIL ){
				dfs(i);
				ok = false;
				break;
			} // end if
		} // end for
		if (ok ) break;
	} // end while

	for (int i = 1; i <= n; i++ ){
		cout << i << ' ' << v[i].ft << ' ' << v[i].rt << endl;
	} // end for
	
	return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> d[120];
bool visit[120];
int cnt = 0;
int fin[120];
int st[120];
void dfs(int p){
	cnt++;
	st[p]=cnt;
	//cout <<"p = "<<p<<" cnt = "<<cnt<<endl;
	visit[p]=true;
	for(int i =0;i <d[p].size();i++){
		if(!visit[d[p][i]]){
			dfs(d[p][i]);
		}
	}
	cnt++;
	fin[p]=cnt;
	return ;
}
int main(){
	int n;
	cin>>n;
	memset(visit, false, sizeof(visit));
	for(int i =0;i < n;i++){
		int u,k;
		cin>>u>>k;
		for(int j =0;j < k;j++){
			int c;
			cin>>c;
			d[u].push_back(c);
		}
	}
	/*cout <<"隣接"<<endl;
	for(int i =1;i <= n;i++){
		for(int j =0;j < d[i].size();j++){
			cout <<" "<<d[i][j];
		}
		cout <<endl;
	}*/
	for(int i =1;i <=n;i++){
		if(!visit[i]){
			dfs(i);
		}
	}
	for(int i =1;i <=n;i++){
		cout <<i<<" "<<st[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	for(int i = 0; i < 20; i++) cin >> n;


	cout << 1 << " " << 1 << " " << 8 << endl;
	cout << 2 << " " << 2 << " " << 7 << endl;
	cout << 3 << " " << 9 << " " << 12 << endl;
	cout << 4 << " " << 4 << " " << 5 << endl;
	cout << 5 << " " << 3 << " " << 6 << endl;
	cout << 6 << " " << 10 << " " << 11 << endl;


    return 0;
}

C++: #include <iostream>
#include <string>

// 深さ優先探索
// Depth First Search(DFS)
// 可能な限り隣接する頂点を訪問する

using namespace std;

const int N_MAX = 100;

enum ColorStatus
{
    WHITE_no_visit,
    GRAY_visit,
    BLACK_finished,
};

struct Node
{
   ColorStatus color;
   // 最初の訪問時刻
   int discoverTime;
   // 訪問完了時刻
   int finishTime;
};

int n; // 頂点数
int M[N_MAX][N_MAX] = { 0 };
Node nodes[N_MAX] = { WHITE_no_visit, 0, 0 };
int times = 0;

// 引数の頂点uを始点にして、深さ探索
// 頂点u->頂点v
void depthFirstSearch(int u)
{
    int v;

    nodes[u].color = GRAY_visit; // 頂点uに訪れた
    nodes[u].discoverTime = ++times; // 訪問時刻のタイムスタンプ
    // 行先頂点v
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0) continue;
        if (nodes[v].color == WHITE_no_visit)
            depthFirstSearch(v);
    }
    nodes[u].color= BLACK_finished; // 頂点uを訪問し終えた。
    nodes[u].finishTime = ++times;
}

void init()
{
    for (int u = 0; u < n; u++)
        if (nodes[u].color == WHITE_no_visit)
            depthFirstSearch(u);

    // 出力
    // 頂点番号 発見時刻 完了時刻
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << nodes[u].discoverTime << " " << nodes[u].finishTime << endl;
    }

}



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u;
        int k;
        cin >> u; // 頂点番号
        cin >> k; // 出自数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    init();


    return 0;
}