Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<bits/stdc++.h>
using namespace std;

static const int N = 100;
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, m[N][N];
int nt[N], color[N];
int d[N], f[N];
int tt;

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

void dfs(int u) {
	for (int i = 0; i < n; i++)
		nt[i] = 0;
	stack<int> s;
	s.push(u);
	color[u] = gray;
	d[u] = ++tt;
	while (!s.empty()) {
		int u = s.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == white) {
				s.push(v);
				color[v] = gray;
				d[v] = ++tt;
			}
		} else {
			s.pop();
			color[u] = black;
			f[u] = ++tt;
		}
	}
}

void dfs_init() {
	tt = 0;
	for (int i = 0; i < n; i++)
		color[i] = white;
	
	for (int i = 0; i < n; i++) {
		if (color[i] == white)
			dfs(i);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

int main() {
	int k, u, v;
	cin >> 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++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			m[u][v] = 1;
		}
	}
	dfs_init();
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u)
{
    for (int v = nt[u]; v < n; v++)
    {
        nt[u] = v + 1;
        if (M[u][v] > 0) return v;
    }
    return -1;
}

void dfs_visit(int r)
{
    for (int i = 0; i < n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while ( !S.empty() )
    {
        int u = S.top();
        int v = next(u);
        if (v != -1)
        {
            if ( color[v] == WHITE)
            {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs()
{
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for (int u = 0; u < n; u++)
    {
        if ( color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main()
{
    int u, k, v;

    cin >> 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++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#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++) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    int u, v, k, i, j;
    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

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

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int d[100];
int f[100];
int now = 1;
void dfs(vector<vector<int> > v, int i) {
  if (d[i]) return;
  d[i] = now++;
  for (int vv : v[i])
    if (i != vv) dfs(v, vv);
  f[i] = now++;
}

int main() {
  int n;
  cin >> n;

  vector<vector<int> > v(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    vector<int> vv(k);
    rep(j, k) {
      cin >> vv[j];
      vv[j]--;
    }
    v[i] = vv;
  }

  rep(i, n) if (!d[i]) dfs(v, i);
  rep(i, n) { printf("%d %d %d\n", i + 1, d[i], f[i]); }
  return 0;
}

C++: /*
 * ALDS1_11_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>
#include<stack>

using namespace std;

int d[101];
int f[101];
int nowTime;

stack<int> st;

void dfsRec(vector<int>* a, int v) {
	if(d[v] > 0) return;
	nowTime++;
	d[v] = nowTime;
	for(int &x:a[v]) {
		dfsRec(a, x);
	}
	nowTime++;
	f[v] = nowTime;
}

void dfsStack(vector<int>* a, int rt) {
	st.push(rt);
	while(!st.empty()) {
		int v = st.top();
		if(d[v] == 0) d[v] = ++nowTime;
		bool found = false;
		for(int &x:a[v]) {
			if(d[x] == 0) {
				st.push(x); found = true; break;
			}
		}
		if(!found) {
			st.pop();
			f[v] = ++nowTime;
		}
	}
}

int main() {
	int n;
	vector<int> adj[101];

	cin >> n;
	for(int i=0; i<n; i++) {
		int v;
		int k;
		cin >> v >> k;
		for(int j=0; j<k; j++) {
			int u;
			cin >> u;
			adj[v].push_back(u);
		}
	}

	for(int i=1; i<=n; i++) {
		if(d[i] ==0) dfsStack(adj, i);
	}

//	for(int i=1; i<=n; i++) {
//		if(d[i] ==0) dfsRec(adj, i);
//	}

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