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)
	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 <algorithm>
struct node{
    long long id;
    long long d;
    long long f;
};
long long n;
long long t = 0;
std::vector<struct node> s;
std::vector<std::vector<long long>> G;
std::vector<long long> used;
void dfs(int i){
    t++;
    s[i].d = t;
    used[i] = 0;
    for(int u: G[i]) {
        if(used[u] == 1) dfs(u);
    }
    t++;
    s[i].f = t;
}
int main(){
    std::cin >> n;
    used.resize(n, 1);
    s.resize(n);
    G.resize(n);
    for(int i =0 ; i < n; i++){
        long long u, k;
        std::cin >> u >> k;
        struct node no;
        u--;
        no.id = u;
        s[u] = no;
        for(int j = 0; j < k; j++){
            long long v;
            std::cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    for(int i = 0; i < n; i++) std::sort(G[i].begin(), G[i].end());
    for(int i = 0; i < n; i++){
        if(used[i] == 1) dfs(i);
    }
    for(int i = 0; i < n; i++){
        std::cout << i + 1 << ' ' << s[i].d << ' ' << s[i].f << std::endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=0;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  t++;
  d[now]=t;
  used[now]=true;
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=t;
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)if(!used[i])dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

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

struct graph {
	struct node {vector<int> v; int d = 0, f;};
	map<int, node> nodes;
	int count = 1;

	void read_all() {
		int n, id, k, v;
		cin >> n;
		while (n--) {
			cin >> id >> k;
			while (k--) {
				cin >> v;
				nodes[id].v.push_back(v);
			}
		}
	}
	void traverse(int id) {
		if (nodes[id].d)
			return;
		nodes[id].d = count++;
		for (int x: nodes[id].v)
			traverse(x);
		nodes[id].f = count++;
	}
	void traverse() {
		for (auto n: nodes)
			traverse(n.first);
	}
	void display_all() {
		for (auto n: nodes)
			cout << n.first << " " << n.second.d << " " << n.second.f << endl;

	}
};

int main() {
	graph g;
	g.read_all();
	g.traverse();
	g.display_all();
}

C++: #include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

class TVertex
{
    int FIndex;
    std::vector<TVertex*> FList;
    int FDiscoveryTime;
    int FFinishTime;

public:
    TVertex(int Index)
     : FIndex(Index), FDiscoveryTime(0), FFinishTime(0)
    {}
    void AddPath(TVertex* Vertex)
    {
        FList.push_back(Vertex);
    }
    void PrintTime(std::ostream& out)const
    {
        out << FIndex << " " << FDiscoveryTime << " " << FFinishTime << std::endl;
    }
    int DepthFirstSearch(int Time)
    {
        if(FFinishTime) return Time;
        FDiscoveryTime = Time++;
        for(std::vector<TVertex*>::iterator It = FList.begin(); It != FList.end(); ++It){
            TVertex* V = *It;
            Time = V->DepthFirstSearch(Time);
        }
        FFinishTime = Time++;
        return Time;
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n+1);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 1);
        assert(Index <= FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v;
            in >> v;
            FTable[Index]->AddPath(FTable[v]);
        }
    }
    void DepthFirstSearch()
    {
        FTable[1]->DepthFirstSearch(1);
    }
    void PrintTime(std::ostream& out)
    {
        for(int i = 1; i < FTable.size(); ++i){
            FTable[i]->PrintTime(out);
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.DepthFirstSearch();
    Graph.PrintTime(std::cout);
    return 0;
    
}