Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

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