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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

std::vector<vector<int> > G;
std::vector<int> flag;
std::vector<int> in;
std::vector<int> out;
int N;
int dfs(int u, int count) {
	if (flag[u] == 1) return -1;
	flag[u] = 1;
	
	in[u] = count;
	for (int i = 0; i < N; ++i) {
		if (flag[i] == 0 && G[u][i] == 1) {
			count = dfs(i, count + 1);
		}
	}
	out[u] = count + 1;
	return count + 1;
}

int main(int argc, char const *argv[]) {
	
	cin >> N;

	for (int i = 0; i < N; ++i) {
		G.push_back(vector<int>());
		flag.push_back(0);
		in.push_back(0);
		out.push_back(0);
		for (int j = 0; j < N; ++j) {
			G[i].push_back(0);
		}
	}

	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--;
			G[u][v] = 1;
		}
	}

	int count = 1;
	for(int i = 0; i < N; i++) {
		int r = dfs(i, count);
		if (r != -1) {
			count = r + 1;
		}
	}

	for (int i = 0; i < N; ++i) {
		cout << i + 1 << " " << in[i] << " " << out[i] << endl;
	}

	return 0;
}

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

using namespace std;

static const int N = 100;
static const int YET = 0;
static const int ALREADY = 1;

int state[N];
int timeTable[N][2];
int timeCount = 0;
int currentV;
stack<int> st;
int M[N][N];

void travel() {
  while(!st.empty()) {
    currentV = st.top();
    st.pop();

    if(state[currentV] == YET) {
      timeCount++;
      timeTable[currentV][0] = timeCount;
      state[currentV] = ALREADY;
      st.push(currentV);

      for(int i = N; i > -1; i--) {
        if(M[currentV][i] == 1 && state[i] == YET) {
          st.push(i);
        }
      }
    }
    else if(timeTable[currentV][1] == 0){
      timeCount++;
      timeTable[currentV][1] = timeCount;
    }
  }
}
int main(void) {


  int n, u, k, v;

  cin >> n;

  //?????????
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

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

  st.push(0);
  travel();
  for(int i = 0; i < N; i++) {
    if(state[i] == YET) {
      st.push(i);
      travel();
    }
  }


  for(int i = 0; i < n; i++) {
    cout << i + 1 << " " << timeTable[i][0] << " " << timeTable[i][1] << endl;
  }
  return 0;
}

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

static const int MAX_NUM = 100;

void dsf_cal(int matrix[][MAX_NUM + 1], int state[], int time[][2], int index, int num)
{
    static int t = 0;
    stack<int> S;

    S.push(index);
    state[index]   = 1;
    time[index][0] = t;
    ++t;

    while (S.empty() != true) {
        int i;
        int target = S.top();
        for (i = 0; i < num; i++) {
            if (state[i] == 0) {
                S.push(i);
                state[i]   = 1;
                time[i][0] = t;
                ++t;
                break;
            }
        }
        if (i == num) {
            time[target][1] = t;
            ++t;
            S.pop();
        }
    }

    return;
}

void DSF(int matrix[][MAX_NUM + 1], int num)
{
    int state[MAX_NUM]   = {0};
    int time[MAX_NUM][2] = {0};

    for (int i = 0; i < num; i++) {
        if (state[i] == 0) {
            dsf_cal(matrix, state, time, i, num);
        }
    }

    for (int i = 0; i < num; i++) {
        printf("%d %d %d\n", i, time[i][0], time[i][1]);
    }

    return;
}

int main(void)
{
    int num;
    int index, elemNum;
    int matrix[MAX_NUM + 1][MAX_NUM + 1] = {0};

    scanf("%d", &num);
    for (int i = 0; i < num; i++) {
        scanf("%d %d", &index, &elemNum);
        for (int j = 0; j < elemNum; j++) {
            scanf("%d", matrix[i+1][j]);
        }
    }

    DSF(matrix, num);

    return 0;
}