Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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

using vvb = std::vector<std::vector<bool>>;

struct TimeStamp
{
    int discovered;
    int finished;
};

std::vector<TimeStamp> dfs(const vvb& edges)
{
    using namespace std;

    int time {1};
    const int n = edges.size();
    stack<int> st;
    vector<bool> reached(n);
    vector<TimeStamp> times(n);

    //すべての辺について行う
    for (int i = 0; i < n; ++i)
    {
        if (reached[i])
            continue;

        times[i].discovered = time++;
        st.push(i);
        
        //点iからつながるすべての辺を調べる
        while (!st.empty())
        {
            int top = st.top();
            for(int i = 0; i < n; ++i)
                if (!reached[i] && edges[top][i])
                {
                    reached[i] = true;
                    times[i].discovered = time++;
                    st.push(i);
                    break;
                }

            //その点からの探索候補がなければ前の点に戻る
            if (top == st.top())
            {
                times[top].finished = time++;
                st.pop();
            }
        }
    }

    return times;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    vvb edges(n, vector<bool>(n));

    //読み込み
    for (int i = 0; i < n; ++i)
    {
        int u, k;
        cin >> u >> k;

        for (int j = 0; j < k; ++j)
        {
            int v;
            cin >> v;
            edges[u - 1][v - 1] = true;
        }
    }

    auto times = dfs(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i + 1 << " " << times[i].discovered << " " << times[i].finished << endl;
    }
}

int main()
{
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
int p=0;
int d[200],f[200];
void dfs(const Graph &G, int v) {
    if (!seen[v]) d[v]=p+1;
    seen[v] = true; // v を訪問済にする
    p++;f[v]=p;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) {
            continue; // next_v が探索済だったらスルー
        }
        dfs(G, next_v); // 再帰的に探索
    }
    p++;f[v]=p;
}

int main() {
   int n;
   cin >> n;
   Graph G(n+1);
   for (int i=0; i<n; i++) {
       int u,k;
       cin >> u >> k;
       for (int j=0; j<k; j++) {
           int v;
           cin >> v;
           G[u].push_back(v);
       }
   }
   seen.assign(n+1,false);
   for (int i=1; i<n+1; i++) {
       if (!seen[i]) {
           dfs(G,i);
       }
   }
   for (int i=1; i<n+1; i++) {
       cout << i << " " << d[i] << " " << f[i] << 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;
}

C++: #include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;

vector<int> d, f;
vector<bool> seen;
void dfs(Graph &G, int v, int &ptr){
  seen[v] = true;
  d[v] = ptr++;
  for (auto next_v : G[v]){
    if (seen[next_v]) continue;
    dfs(G, next_v, ptr);
  }
  f[v] = ptr++;
}

int main() {
  int n;
  cin >> n;
  Graph G(n);
  rep(i, n){
    int u, k;
    cin >> u >> k;
    rep(j, k){
      int v;
      cin >> v;
      G[u-1].push_back(v-1);
    }
  }
  seen.assign(n, false);
  d.assign(n, 0);
  f.assign(n, 0);
  int ptr = 1;
  rep(i, n){
    if (seen[i]) continue;
    dfs(G, i, ptr);
  }
  rep(i, n){
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }
  
  return 0;
}