Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

static const int DFS_VISIT_NO   = 0;
static const int DFS_VISIT_NOW  = 1;
static const int DFS_VISIT_DONE = 2;

static int g_time = 0;
static int g_setime[100][2] = {0};

void DfsVisit(vector<int> &graph, int node, vector<int> &state)
{
    int i;
    int nnum;
    int target;

    ++g_time;
    g_setime[node][0] = g_time;

    state[node] = DFS_VISIT_NOW;
    
    nnum = graph[node].size();

    for (i = 0; i < nnum; i++) {
        target = graph[node][i];
        if (state[target] != DFS_VISIT_DONE) {
            DfsVisit(graph, target, state);
        }
    }

    state[node] = DFS_VISIT_DONE;

    ++g_time;
    g_setime[node][1] = g_time;

    return;
}


void DFS(vector<int> &graph, int num)
{
    int i;
    vector<int> state;

    for (i = 0; i < num; i++) {
        state[i] = DFS_VISIT_NO;
    }

    for (i = 0; i < num; i++) {
        if (state[i] == DFS_VISIT_NO) {
            DfsVisit(graph, num, i, state);
        }
    }

    for (i = 0; i < num; i++) {
        printf("%d %d %d\n", i+1, g_setime[i][0], g_setime[i][1]);
    }

    return;
}

int main(void)
{
    int i, j;
    int target, tnum, node;
    int num;

    scanf("%d", &num);
    vector<int> graph[num];

    for (i = 0; i < num; i++) {
        scanf("%d" "%d", &target, &tnum);
        --target;
        for (j = 0; j < tnum; j++) {
            scanf("%d", &node);
            --node;
            graph[target].push_back(node);
        }
    }

    DFS(graph, num);
}

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


using namespace std;


stack<int> visiting;

#define MAX 100
bool adj[MAX + 2][MAX + 2];
int d[MAX + 1], f[MAX + 1];
bool discovered[MAX + 1];
int tt, n;


void dfs(int v)
{
    visiting.push(v);
    discovered[v] = true;
    d[v] = ++tt;

    while (!visiting.empty()) {
        int now = visiting.top();
        int i;
        for (i = 1; i <= n; i++) {
            if (adj[now][i] && !discovered[i])
                break;
        }

        if (!discovered[i] && i <= n) {
            d[i] = ++tt;
            visiting.push(i);
            discovered[i] = true;
        } else {
            f[now] = ++tt;
            visiting.pop();
        }
    }
}


int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            adj[id][v] = true;
        }

        discovered[i] = false;
    }

    for (int i = 1; i <= n; i++)
        if (!discovered[i])
            dfs(i);


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

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
bool ok[10005];
int d[10005];
int f[10005];
vector<int> e[10005];
int step=0;
void dfs(int i){
	ok[i]=1;
	step++;
	d[i]=step;
	for(int j=0;j<e[i].size();j++)
		if(!ok[e[i][j]])
			dfs(e[i][j]);
	step++;
	f[i]=step;
}
void solve(){
	for(int i=1;i<=n;i++)if(!ok[i])dfs(i);
	for(int i=1;i<=n;i++)
		cout<<i<<' '<<d[i]<<' '<<f[i]<<"\n";
}
int main(){
//	freopen("a.txt","r",stdin);
	cin>>n;
	int u,k,v;
	for(int i=1;i<=n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++)cin>>v,e[u].push_back(v);
	}
	solve();
	return 0;
}

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

using namespace std;

struct Edge
{
	int to;
};

vector<vector<int>> DFS(vector<vector<Edge>>& G)
{
	int timecounter = 0;
	vector<vector<int>> result;
	result = vector<vector<int>>(2, vector<int>(G.size(), 0));
	vector<int> prev(G.size(),0);
	
	for(int i = 0; i < G.size(); i++){
		int next = i + 1;
		while(result[1][i] == 0){
			int tmp;
			if(result[0][next - 1] == 0){
				timecounter += 1;	
				result[0][next - 1] = timecounter;
			}

			if(G[next - 1].empty() || result[0][G[next - 1].begin()->to - 1]){
				if(result[1][next - 1] == 0){
					timecounter += 1;
					result[1][next - 1] = timecounter;
				}
				next = prev[next - 1];
			}else{
				tmp = G[next - 1].begin()->to;
				G[next - 1].erase(G[next - 1].begin());
				if(tmp != next)
					prev[tmp - 1] = next;
				next = tmp;
			}
			//cout << next << endl;
		}
	}
	return result;
}

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

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

	vector<vector<int>> timestump = DFS(AdjList);
	
	for(int i = 0; i < AdjList.size(); i++){
		cout << i + 1 << " " << timestump[0][i] << " " << timestump[1][i] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
int g[101][101], d[101], f[101], vis[101];
int time = 0, n;

void dfs(int u)
{
  if (vis[u] != 0) return;
  vis[u] = 1;
  d[u] = ++time;
  for (int i = 0; i < n; i++)
  {
    if (g[u][i] == 1)
    {
      dfs(i);
    }
  }
  vis[u] = 2;
  f[u] = ++time;
}

int main()
{
  memset(g, 0, sizeof(g));
  memset(vis, 0, sizeof(vis));
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    int u, adj_num;
    scanf("%d%d", &u, &adj_num);
    while (adj_num--)
    {
      int v;
      scanf("%d", &v);
      g[u - 1][v - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (!vis[i]) dfs(i);
  }
  for (int i = 0; i < n; i++)
  {
    printf("%d %d %d\n", i + 1, d[i], f[i]);
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int d[105] = { -1 }, f[105] = { -1 };
int n = -1;
int mat[105][105] = { { 0 } };
int visited[105] = { 0 };

void dfs(int v, int& now)
{
  d[v] = now;
  visited[v] = 1;
  ++now;
  for (int u = 1; u <= n; ++u) {
    if (mat[v][u] && !visited[u]) {
      dfs(u, now);
    }
  }
  f[v] = now;
  ++now;
}

int main()
{
  fscanf(stdin, "%d", &n);
  for (int i = 0; i < n; ++i) {
    int u = -1, k = -1, v = -1;
    fscanf(stdin, "%d %d", &u, &k);
    for (int j = 0; j < k; ++j) {
      fscanf(stdin, "%d", &v);
      mat[u][v] = 1;
    }
  }
  int now = 1;
  for (int v = 1; v <= n; ++v) {
    if (!visited[v]) {
      dfs(v, now);
    }
  }
  for (int i = 0; i < n; ++i) {
    fprintf(stdout, "%d %d %d\n", i + 1, d[i + 1], f[i + 1]);
  }
  return 0;
}