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<bits/stdc++.h>
#include<string.h>
#define MAX 101
#define WHITE -1
#define GRAY 2
#define BLACK 1
using namespace std;

int G[MAX][MAX]={},d[MAX]={},f[MAX]={},color[MAX]={},times=0,Adj[MAX]={};

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

void visit(int u,int n){
    color[u]=GRAY;
    d[u]=++times;
    int v=1;
    while(v<=n){
        if(G[u][v]>0){
            if(color[v]==WHITE)visit(v,n);
        }
        v++;
    }
    color[u]=BLACK;
    f[u]=++times;
}

void dfs(int V[],int n){
    int u;
    for(u=1;u<=n;u++){
        color[u]=WHITE;
    }
    times =0;
    for(u=1;u<=n;u++){
        if(color[u]==WHITE)visit(u,n);
    }
}

int main(){
  int n,i,k,j,A,B,V[MAX]={};
  cin>>n;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
        G[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    cin>>A>>k;
    for(j=0;j<k;j++){
      cin>>B;
      G[A][B]=1;
    }
  }
  dfs(V,n);
  print(n);
}

C++: 
/*
Problem

Category
DFS

URL:
http://judge.u-aizu.ac.jp/onlinejudge/submission.jsp#submit/ALDS1_11_B

考察:


Date: 2020/04/14
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int n;
int counter = 1;
vector<vector<int>> ALL;
// vector<int> isVisited;
vector<int> d;
vector<int> f;
vector<int> visited;

/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>n;
    d.resize(n);
    f.resize(n);
    for(int i=0; i<n; ++i) {
        int u, k;
        cin>>u>>k;
        u--;
        vector<int> AL;
        for(int j=0; j<k; ++j) {
            int v;
            cin>>v;
            AL.push_back(--v);
        }
        ALL.push_back(AL);
    }
}

void dfs(int v) {    
    d[v] = counter++;
    visited.push_back(v);
    for(auto u: ALL[v]) {
        if (find(visited.begin(), visited.end(), u) == visited.end()) {
            dfs(u);
        }
    }
    f[v] = counter++;
}


void solve() {
    for(int u=0; u<n; ++u) {
        if (find(visited.begin(), visited.end(), u) == visited.end()) {
            dfs(u);
        }
    }
    for(int i=0; i<n; ++i ) {
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

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

struct Node{
    bool comp;
    int starttime, endtime;
};

int Time = 1;

void setTime(queue<int> q[], stack<int> t, Node l[]){
    if(Time == 1){
        t.push(1);
        l[0].starttime = Time++;
        setTime(q, t, l);
    }

    if(t.size() == 0){
        return;
    }

    int index = t.top() -1;

    // if(l[index].comp){
    //     cout << index << endl;
    //     t.pop();
    //     setTime(q, t, l);
    // }

    if(q[index].size() == 0){
        t.pop();
        l[index].endtime = Time++;
        l[index].comp = true;
        setTime(q, t, l);
    } else {
        int val = q[index].front();
        q[index].pop();

        if(l[val - 1].comp) setTime(q, t, l);
        else{
            t.push(val);
            l[val - 1].starttime = Time++;
            setTime(q, t, l);
        }
    }

}

int main(){
    int n, v, k, l;
    cin >> n;
    queue<int> q[n];
    stack<int > timetable;
    Node timelist[n];
    for(int i=0; i<n; i++){
        cin >> v >> k;
        v--;
        timelist[i].comp = false;
        for(int j=0; j<k; j++){
            cin >> l;
            q[v].push(l);
        }
    }

    setTime(q, timetable, timelist);

    for(int i=0; i<n; i++){
        cout << i+1 << " " << timelist[i].starttime << " " << timelist[i].endtime << endl;
    }

    return 0;

}

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

#define MAX 100
static const int WHITE = 0; // not visit
static const int GRAY = 1; // visited
static const int BLACK = 2; // searched

int n;
int M[MAX][MAX] = { 0 };
int color[MAX] = { WHITE };
int d[MAX], f[MAX], tt = 0;
int nt[MAX] = { 0 };

// get vertex next u
int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs() {
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE)  dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
	return;
}

int main() {
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		int k, u;
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}

	dfs();
	return 0;

}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int> > G[101];

int ti = 1;

void dfs(int id) {
	if (d[id]) return ;
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0; i<(int)adj.size(); ++i) {
		dfs(adj[i]);
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	for (int i=1; i<=n; ++i) {
		dfs(i);
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}