Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define MAX 2000000000
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std ;

int d[102] = { 0 }, f[102] = {0};
int M[102][102];

int main() {
	stack<int> stk;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int k,l,m;
		cin >> m;
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> l;
			M[m][l] = 1;
		}
	}
    
	stk.push(1);

    int i = 1,time=1,count=0;
    d[1]=1;
	while (count<n) {
		if (M[stk.top()][i]==1 && d[i]==0) {
			stk.push(i);
			d[stk.top()] = ++time;
			i=1;
		}
		else {
			i++;
			if (i > n) {
				f[stk.top()] = ++time;
				count++;
				stk.pop();
				i=1;
			}
		}
		if(stk.empty()){
		    for(int j=1;j<=n;j++)
		        if(d[j]==0){
		        stk.push(j);
		        d[stk.top()]=++time;
		        i=1;
		        break;
		    }
		}
	}
    
	for (int i = 1;i <= n;i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
  
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#define white 0
#define grey 1
#define black -1
using namespace std;

int a[110][110],n;
int color[110];
int t;
int ts[110],te[110];
int nt[110];

void dfsinit()
{
    for(int i=1;i<=110;i++)
        {
            color[i]=white;
            nt[i]=0;
        }
}

int next(int i)
{
    for(int j=nt[i];j<=n;j++)
    {
        nt[i]=j+1;
        if(a[i][j]) return j;
    }
    return -1;
}

void dfsvisit(int u)
{
    for(int i=1;i<=n;i++)
        nt[i]=0;
    stack<int>s;
    s.push(u);
    ts[u]=++t;
    color[u]=grey;
    while(!s.empty())
    {
       int r=s.top();
       int v=next(r);
       if(v!=-1)
       {
          if(color[v]==white)
          {
              color[v]=grey;
              ts[v]=++t;
              s.push(v);
          }
       }
       else
       {
           color[r]=black;
           te[r]=++t;
           s.pop();
       }
    }
}

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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N,u,k,x,r=0;
vector<int>V[105];
bool f[105]={0};
P c[105];

void dfs(int p)
{
	if(f[p])return;
	r++;
	f[p]=1;
	c[p].first=r;
	for(int i=0;i<V[p].size();i++)
	{
		dfs(V[p][i]);
	}
	r++;
	c[p].second=r;
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d%d",&u,&k);u--;
		for(int j=0;j<k;j++)
		{
			scanf("%d",&x);x--;
			V[u].push_back(x);
		}
	}
	dfs(0);
	for(int i=0;i<N;i++)
		printf("%d %d %d\n",i+1,c[i].first,c[i].second);
	return 0;
}

C++: //Depth First Search
#include <iostream>
#include <vector>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int BLACK = 1;

int color[N] = {WHITE}, d[N] = {}, f[N] = {}, tt = 1;

void dfs(vector<vector<int>> &graph, int u) {
    if(color[u] == BLACK) return;
    color[u] = BLACK;
    d[u] = tt++;
    for(auto v: graph[u]) dfs(graph, v);
    f[u] = tt++;
}

int main() {
    int n;
    cin >> n;
    int u, k, v;
    vector<vector<int>> graph(n);
    for(int i=0; i<n; i++) {
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++) {
            cin >> v;
            v--;
            graph[u].push_back(v);
        }
    }

    for(int i = 0; i < n; i++)
        dfs(graph, i);

    for(int i = 0; i < n; i++)
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    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, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u){
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v]) 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 {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	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 n, k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	cin >> u >> k;
	u--;
	for(int i = 0; i < k; i++) {
	    cin >> v;
	    v--;
		M[u][v] = 1; 
	}
	dfs();
	return 0;
}