Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

static const int N = 100;

vector<int> d(N, 0), f(N, 0);
vector< vector<int> > Adj(N, vector<int>());
int t = 0;
void dfs(int node);

int main() {

    int n; cin >> 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--;
            Adj[u].push_back(v);
        }
    }

    for (int i = 0; i < n; i++) {
        if (d[i] == 0) {
            dfs(i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << '\n';
    }

}

void dfs(int node) {

    if (!d[node]) {
        t++;
        d[node] = t;
    }
    for (int i = 0; i < Adj[node].size(); i++) {
        int v = Adj[node][i];
        if (d[v] != 0) {
            continue;
        }
        else {
            t++;
            d[v] = t;
            dfs(v);
        }
    }
    t++;
    f[node] = t;
}

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

struct VRTX {
	int dt, ft, v[101];
};

int curtime = 1;
VRTX ver[101];

void depthFirstSearch(int u);

int main() {
	int i, j, n, u, k;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> ver[u].v[j];
		}
	}

	depthFirstSearch(1);

	for (i = 1; i <= n; i++) {
		cout << i << " " << ver[i].dt << " " << ver[i].ft << endl;
	}

	return 0;
}

void depthFirstSearch(int u) {

	if (ver[u].dt == 0) {
		int i = 0;

		ver[u].dt = curtime++;

		while (ver[u].v[i] != 0) {
			depthFirstSearch(ver[u].v[i]);
			i++;
		}

		ver[u].ft = curtime++;

		return;
	}
	return;
}

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

using namespace std;

int N,k[1000];
int v[1000][1000];
int found[1000] = {0},ended[1000] = {0};
int keep;
int checking=0;

void dfs(int cur);

int main() {
	cin >> N;
	for(int i=1;i<N+1;i++) {
		cin >> keep >> k[i];
		for(int j=1;j<k[i]+1;j++) {
			cin >> v[i][j];

		}
	}
	dfs(1);
	while(true) {
		//cout << "processing..." << endl;
		bool flag = false;
		int key = 1;
		for(int i=1;i<N+1;i++) {
			if(found[i] == 0) {
				flag = true;
				key = i;
				break;
			}
		}
		if(flag) {
			dfs(key);
		} else {
			break;
		}
	}
	
	
	for(int i=1;i<N+1;i++) {
		cout << i << " " << found[i] << " " << ended[i] << endl;
	}
	

}

void dfs(int cur) {
	//cout << "process ended" << endl;
	if(!found[cur]) {
		checking++;
		//cerr << "visiting: " << cur << " " << "time: " << checking << endl;
		found[cur] = checking;

	}
	for(int dst=1;dst<N+1;dst++) {
		bool flag = false;
		for(int i=1;i<k[cur]+1;i++) {
			if(v[cur][i] == dst) flag = true;
		}
		if((flag) && (dst != cur) && (!found[dst])) dfs(dst);
	}
	if(!ended[cur]) {
		checking++;
		//cerr << "ended: " << cur << " " << "time: " << checking << endl;
		ended[cur] = checking;
	}
}
/*
????????£????????????40?????????????????????????????????????????????????°?????????????????????????
*/

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<int> G[N];
int visited[N], checked[N];

int find_no_visited(int n) {
	int ret = -1;
	rep(i, n) {
		if (visited[i]) continue;
		ret = i;
		break;
	}
	return ret;
}

int find_no_visited(int n, int i) {
	int ret = -1;
	for (auto j : G[i]) {
		if (visited[j]) continue;
		ret = j;
		break;
	}
	return ret;
}

int main() {
	int n; cin >> n;
	rep(i, n) {
		int _, n2; cin >> _ >> n2;
		rep(j, n2) {
			int k; cin >> k; k--;
			G[i].push_back(k);
		}
	}
	rep(i, n) { visited[i] = 0; checked[i] = 0;}

	stack<int> S;
	int T = 1;
	S.push(0);
	visited[0] = T;
	while (true) {
		T++;
		if (S.empty()) {
			int i = find_no_visited(n);
			if (i != -1) {
				visited[i] = T;
				S.push(i);
				continue;
			}
			else
				break;
		}
		int i = find_no_visited(n, S.top());
		if (i != -1) {
			visited[i] = T;
			S.push(i);
		}
		else {
			checked[S.top()] = T;
			S.pop();
		}
	}
	rep(i, n) cout << i+1 << ' ' << visited[i] << ' ' << checked[i] << endl;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

ll d[100], f[100], now, cnt;
char flag[100];
vector<int> vec[100];

int dfs(int n) {
  if(f[n]) return 0;
  cnt++;
  d[n] = cnt;
  vector<int>::iterator it;
  for(it = vec[n].begin(); it != vec[n].end(); ++it) {
    if(!f[*it]) dfs(*it);
  }
  ++cnt;
  f[n] = cnt;
  return 0;
}

int main(void) {
  ll n;
  scanf("%d", &n);
  now = 0, cnt = 0;
  rep(i, n) flag[i] = 0;
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
    sort(vec[u].begin(), vec[u].end());
  }
  dfs(0);
  rep(i, n) printf("%d %lld %lld\n", i + 1, d[i], f[i]);
  return 0;
}