Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
//
#define N 105
vector<int> nebors[N];//start from 1
int start[N]; // start form 1
int end[N]; //end with 1
int vis_nei[N]; // neighbor
stack<int> s;
void dfs(int k,int d){
	d  = 1;
	s.push(1);
	start[1] = d;
	while(!s.empty()){
		//see the top
		int k = s.top(); // add-- deal with null
		if(vis_nei[k] == 1) {
			int m = s.top(); s.pop();
			end[m] = (++d);
		} else {
			//printf("k:%d\n",k);
			for(int i = 0; i<nebors[k].size(); i++){
				int temp = nebors[k].at(i);
				s.push(temp);
				if(start[temp] == -1){
					start[temp] = (++d);
				}
			}
			vis_nei[k] = 1;
		}
		
	}
	
	//check the adjencit list
	/*for(int i = 0; i<nebors[k].size(); i++){
		int temp = nebors[k].at(i);
		
		
	}*/
	//end[k] = 9-d;
}

int main(){
	int n;
	scanf("%d",&n);
	memset(start,-1,sizeof(start));
	memset(end,-1,sizeof(end));
	memset(vis_nei,-1,sizeof(vis_nei));
	//vis_nei
	for(int i = 1; i<=n; i++){
		int id,num;
		scanf("%d %d",&id, &num);
		for(int j = 0; j<num; j++){
			int temp;
			scanf("%d",&temp);
			nebors[id].push_back(temp);
			//nebors[temp].push_back(id);
		}
	}
	dfs(1,1);
	
	for(int i = 1; i<=n; i++){
		printf("%d %d %d\n",i,start[i],end[i]);
	}
}

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

struct node {
	int num;
	std::vector<int> child;
};

int recurcive(node nodes[],int d[100], int f[100], int n, int count) {
	d[n] = count++;
	for (size_t i = 0; i < nodes[n].child.size(); i++) {
		if (d[nodes[n].child[i]] == 0) {
			count = recurcive(nodes, d, f, nodes[n].child[i], count);
		} else {
			nodes[n].child.erase(std::find(nodes[n].child.begin(), nodes[n].child.end(), nodes[n].child[i]));
		}
	}
	f[n] = count++;

	return count;
}

int main() {
	int node_num;
	node nodes[100];
	std::cin >> node_num;

	for (int i = 0; i < node_num; i++) {
		int n, num;
		std::cin >> n >> num;
		for (int j = 0; j < num; j++) {
			int val;
			std::cin >> val;
			nodes[n - 1].child.push_back(val - 1);
		}
	}

	std::stack<int> st, st2;
	std::vector<int> gone;
	int d[100], f[100];
	int count = 1;

	for (int i = 0; i < 100; i++)
		d[i] = f[i] = 0;

	for (int i = 0; i < node_num; i++) {
		if (d[i] == 0) {
			count = recurcive(nodes, d, f, i, count);
		}
	}

	for (int i = 0; i < node_num; i++) {
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
	
	return 0;
}

C++: #include <cstdio>

typedef struct{
	bool isVisited;
	int degree;
	int start;
	int end;
	int *neighbors;
} node;

int count = 0;

void dfs(node* nodes, int id){
	nodes[id].isVisited = true;
	if (nodes[id].start == 0) nodes[id].start=count;
	for (int i=0; i<nodes[id].degree; i++){
		if (!nodes[nodes[id].neighbors[i]].isVisited){
			count ++;
			dfs(nodes, nodes[id].neighbors[i]);
		}
	}
	count++;
	nodes[id].end = count;
}

int main(){
	int n, d, r, id;
	node *nodes;

	scanf("%d", &n);
	nodes = new node[n+1];
	nodes[0].start=0;
	nodes[0].degree=n;
	nodes[0].neighbors = new int[n];
	for (int i=0;i<n;i++){
		nodes[0].neighbors[i]=i;
	}
	for (int i=1; i<n+1;i++){
		nodes[i].isVisited=false;
		scanf("%d %d", &r, &d);
		nodes[i].degree=d;
		nodes[i].neighbors = new int[d];
		nodes[i].start = 0;
		
		for (int j=0;j<d;j++){
			scanf("%d", &id);
			nodes[i].neighbors[j] = id;
		}
	}

	dfs(nodes, 0);
	for (int i=1; i<n+1;i++){
		printf("%d %d %d\n", i, nodes[i].start, nodes[i].end);
		delete []nodes[i].neighbors;
	}
	delete []nodes;
	return 0;
}

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

using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int i,int& clock) //??¶????????°?????\???????????¨
{
    clock++;
    Visited[i]=true;
    dTime[i]=clock; //???????????°??¶??´
    for(int j=0;j<Adjacency[i].size();j++)
    {
        if(Visited[Adjacency[i][j]]==true) continue;
        dfs(Adjacency[i][j],clock);
    }
    clock++; //???????????????????¢????
    fTime[i]=clock;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

C++: #include <cstdio>
#include <cstring>

const int MAX = 100;
static int time = 0;
int adj[MAX][MAX];
int discover[MAX];
int finish[MAX];

void visit(int node, int n)
{
  ++time;
  discover[node] = time;

  for (int i = 0; i < n; ++i)
  {
    if (adj[node][i] == 1 && discover[i] == 0)
      visit(i, n);
  }

  ++time;
  finish[node] = time;
}

int main()
{
  std::memset(adj, 0, sizeof(adj));
  std::memset(discover, 0, sizeof(discover));
  std::memset(finish, 0, sizeof(finish));

  int n;
  scanf("%d", &n);

  int u, k, v;
  for (int i = 0; i < n; ++i)
  {
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; ++j)
    {
      scanf("%d", &v);
      adj[u - 1][v - 1] = 1;
    }
  }

  for (int i = 0; i < n; ++i)
  {
    if (discover[i] == 0)
      visit(i, n);
  }

  for (int i = 0; i < n; ++i)
    printf("%d %d %d\n", i + 1, discover[i], finish[i]);

  return 0;
}