Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

int G[110][110];///构造图
bool vis[110];///设置是否访问过
int tot;///设置访问次序
int st[110],ed[110];///设置顶点的发现时刻，顶点的结束时刻
int n;

int next_(int u){
    for(int i=1;i<=n;i++){
        if(G[u][i]&&vis[i]==0)
            return i;
    }
    return -1;
}

void DFS(int r){
    stack<int> s;
    s.push(r);
    vis[r]=true;
    st[r]=++tot;
    while(!s.empty()){
        int u=s.top();
        int v=next_(u);
        if(v!=-1){
            if(vis[v]==false){
                vis[v]=true;
                st[v]=++tot;
                s.push(v);
            }
        }
        else{
            s.pop();
            ed[u]=++tot;
        }

    }
}

void DFS_Visit(){
    memset(st,0,sizeof(st));
    memset(ed,0,sizeof(ed));
    memset(vis,0,sizeof(vis));
    tot=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==false)
            DFS(i);
    }
    for(int i=1;i<=n;i++){
        printf("%d %d %d\n",i,st[i],ed[i]);
    }
}

int main(){
    scanf("%d",&n);
    memset(G,0,sizeof(G));

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

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

using namespace std;

struct Node {
    int visit = 0;
    vector<int> next;
    int s = 0;
    int start = 0;
    int end = 0;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].visit == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        st.push(s);
        while (!st.empty()) {
            temp = st.top();
            if (node[temp].s < node[temp].next.size()) {
                if (node[node[temp].next[node[temp].s]].visit == 0) {
                    node[node[temp].next[node[temp].s]].start = time++;
                    node[node[temp].next[node[temp].s]].visit = 1;
                    st.push(node[temp].next[node[temp].s++]);
                }
                else {
                    node[temp].s++;
                }
            }
            else {
                node[temp].visit = 2;
                node[temp].end = time++;
                st.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t){
    visited[s]=true;
    ans[s].first = t;
    REP(i,g[s].size()){
        if(visited[g[s][i]])continue;
        t = dfs(g[s][i],t+1);
    }
    t++;
    ans[s].second = t;
    return t;
}


int main() {
    int n;
    cin >> n;
    REP(i,n){
        int u,m;
        cin >> u >> m;
        REP(j,m){
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    dfs(1,1);
    for(int i=1;i<=n;i++){
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

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

struct node {
    int start = 0;
    int end = 0;
};

void depth_search(map<int, vector<int> > &a, map<int, node> &nodes, int &time, int current) {
    time++;
    nodes[current].start = time;
    for (int i=0; i<a[current].size(); i++) {
        if ( nodes[a[current][i]].start == 0 ) {
            depth_search(a, nodes, time, a[current][i]);
        }
    }
    time++;
    nodes[current].end = time;
}

int main() {
    int n;
    cin >> n;
    map<int, vector<int> > a;
    for (int i=0; i<n; i++) {
        int u, k, v;
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            a[u].push_back(v);
        }
    }
    
    int time = 0;
    map<int, node> nodes;
    for (int i=0; i<n; i++) {
        node nd; 
        nodes[i] = nd;
    }
    depth_search(a, nodes, time, 1);
    
    for (int i=1; i<=n; i++) {
        cout << i << " " << nodes[i].start << " " << nodes[i].end << endl;
    }
}

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

const int MAX_N = 100;

struct Node {
  int v;
  int firstVisitedTime;
  int lastVisitedTime;
  bool visited;
};

void visit(int *count, int n, std::vector<std::list<int> *> *graph, std::vector<struct Node *> *nodes) {
  (*count)++;
  
  struct Node *node = nodes->at(n);

  if (!node->visited) {
    node->firstVisitedTime = *count;
    node->visited = true;
  }  

  //  std::cout << (*count) << " = " << n << std::endl;

  std::list<int> *neighbors = graph->at(n);

  while (!neighbors->empty()) {
    int v = neighbors->front();
    neighbors->pop_front();
    
    if (!nodes->at(v)->visited) {
      visit(count, v, graph, nodes);
    }
  }

  (*count)++;
  node->lastVisitedTime = (*count);

  //  std::cout << (*count) << " = " << n << std::endl;
}

int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);  

  int n = 0;
  std::cin >> n;

  std::vector<std::list<int> *> *graph = new std::vector<std::list<int> *>(n + 1);
  std::vector<struct Node *> *nodes = new std::vector<struct Node *>(n + 1);
  
  for (int i = 1; i <= n; i++) {
    int v = 0;
    std::cin >> v;

    int k = 0;
    std::cin >> k;

    std::list<int> *neighbors = new std::list<int>();

    for (int i = 0; i < k; i++) {
      int a = 0;
      std::cin >> a;

      neighbors->push_back(a);
    }

    graph->at(i) = neighbors;

    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->v = i;
    node->firstVisitedTime = 0;
    node->lastVisitedTime = 0;
    node->visited = false;
    
    nodes->at(i) = node;
  }

  int count = 0;
  int start = 1;

  visit(&count, start, graph, nodes);  

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
        
    std::cout << node->v << " " << node->firstVisitedTime << " " << node->lastVisitedTime << std::endl;
  }
  
  return 0;
}