Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dfs(const vector<vector<int>>& edges, vector<int>& ds, vector<int>& fs, int u, int& t) {
    if (ds[u] > 0) {
        return;
    }
    ds[u] = ++t;
    for (auto v : edges[u]) {
        dfs(edges, ds, fs, v, t);
    }
    fs[u] = ++t;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            edges[u].push_back(v);
        }
        sort(begin(edges[u]), end(edges[u]));
    }
    vector<int> ds(n, -1);
    vector<int> fs(n, -1);
    int t = 0;
    for (int i = 0; i < n; i++) {
        dfs(edges, ds, fs, i, t);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}

C++: #include <iostream>

using namespace std;

	int TIME = 0;
	int d[101];
	int f[101];
	int num;
	int graph[101][101] = {0};

void dfs(int x){
	TIME++;
	d[x] = TIME;

	for(int i=1;i<=num;i++){
		if(graph[x][i] == 1 && d[i]==0){
			printf("%d -> %d\n",x,i);
			dfs(i);
		}
	}
	f[x] = ++TIME;
}

int main(){
	int hon;
	int eda;
	int ver;

	cin>>num;
	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}

	dfs(1);

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

	return 0;
}

C++: #include <iostream>

using namespace std;

int V[100][100];
int n;

int d[100];
int f[100];

int t = 1;
void dfs(int src){
  t++;
  for(int i=1;i<=n;i++){
    if(V[src][i] != 0 && !d[i]){
      d[i] = t;
      dfs(i);
      t++;
    }
  }
  f[src] = t;
}
int main(){
  int  src, dst, num, non_visited;
  cin >> n;
  for(int i=1;i<=n;i++){
    d[i] = 0; f[i] = 0;
  }
  for(int i=1;i<=n;i++){
    cin >> src >> num;
    for(int j=0;j<num;j++){
      cin >> dst;
      V[src][dst] = 1;
    }
  }
  non_visited = 1;
  do{
    d[non_visited] = t;
    dfs(non_visited);
    non_visited = 0;
    for(int i=1;i<=n;i++){
      if(!d[i]){
        non_visited = i;
        break;
      }
    }
    t++;
  }while(non_visited);

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

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;
}