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++: //
//  main.cpp
//  depth_first_search
//
//  Created by ???????????? on 2017/10/22.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

#define n_max 100

using namespace std;

int n, t = 0;
int M[n_max][n_max], color[n_max], d[n_max], f[n_max];

void encode_graph(int n){
    int i, j, id, num, node;
    
    //initialize with 0
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    
    for (i = 0; i < n; i++){
        scanf("%d", &id);
        scanf("%d", &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            M[id-1][node-1] = 1;
        }
    }
}

void dfs(int u){
    color[u] = 1;
    d[u] = ++t;
    for (int v = 0; v < n; v++){
        if((M[u][v]) && (color[v] == 0)){
            dfs(v);
        }
    }
    color[u] = 2;
    f[u] = ++t;
}

void dfs_init(int n){
    for(int i = 0; i < n ; i++){
        color[i] = 0;
    }
    dfs(0);
}


int main(int argc, const char * argv[]) {
    scanf("%d", &n);
    
    encode_graph(n);
    
    dfs_init(n);
    
    for(int i = 0; i < n; i++){
        cout<<i+1<<" "<<d[i]<<" "<< f[i]<<endl;
    }
    
//    std::cout << "Hello, World!\n";
    return 0;
}

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

int n;
int k;
int color[100];
int a[100],b[100],c;
int adj[110][110];

void deepread(int k){
  int h;
  color[k]=1;
  a[k]=++c;
  for(h=0;h<n;h++){
    if(adj[k][h]==0){
      continue;
    }
    if(color[h]==0){
      deepread(h);
    }
  }
  color[k]=3;
  b[k]=++c;
}

void deep(){
  for(int i=0;i<n;i++){
    color[i]=0;
  }
  c=0;
  for(int k=0;k<n;k++){
    if(color[k]==0)deepread(k);
  }
  for(int k=0;k<n;k++){
    cout<<k+1<<" "<<a[k]<<" "<<b[k]<<endl;
  }
}


int main(){
  int num;
  cin>>n;
  int rin;
  int i=0,j=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      adj[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    cin>>num>>k;
    num--;
    for(j=0;j<k;j++){
      cin>>rin;
      rin--;
      adj[num][rin]=1;
    }
  }
  /*for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)cout<<" ";
      cout<<adj[i][j];
    }
    cout<<endl;
    }*/

  deep();
  return 0;
}

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

int t=0,k,n;
int gone[100+10]={},a[100+10][100+10]={},d[200+10],f[200+10];

void dfs(int cur){
    if(gone[cur]!=1){
        t+=1;
        d[cur]=t;
        gone[cur]=1;
    }
    for(int m=1;m<=n;m++){
        if(a[cur][m]==1){
            if(gone[m]==0){
                dfs(m);
            }
        }
    }
    t+=1;
    f[cur]=t;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        int u,p;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> p;
            a[i][p]=1;
        }
    }
    for(int q=1;q<=n;q++){
        if(gone[q]!=1) dfs(q);
    }
    for(int r=1;r<=n;r++){
        cout << r << " " << d[r] << " " << f[r] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  //cout << n << endl;
  for(int i=0;i<n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u-1][v-1]=1;
    }
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<stack>

#define Max 100
#define white 0
#define gray 1
#define black 2
using namespace std;
int dia=0;
int d[Max+1],f[Max+1];
	bool g[Max+1][Max+1];
	int color[Max+1];
	
void dft(int a,int n){
	int i;
	color[a]=gray;
	d[a]=++dia;
	for(i=1;i<=n;i++){
		if(g[a][i] && color[i]==white)
			dft(i,n);	
		}
		color[a]=black;
		f[a]=++dia;
	
}
void defa( int n){
	int i;
	for( i=1;i<=n;i++)
	color[i]=white;
	for(i=1;i<=n;i++){
		if(color[i]==white)
		dft(i,n);
	}
}
main(){
	int j,i,n,u,k,v;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)
		g[i][j]=false;
	}
	for(i=1;i<=n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
		scanf("%d",&v);
		g[u][v]=true;
		}
	}
	defa(n);
	for(i=1;i<=n;i++)
	printf("%d %d %d\n",i,d[i],f[i]);
	
	return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[100]={0}, p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}