Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

struct VRTX {
	int dt, ft, v[101];
};

int curtime = 1;
VRTX ver[101];

void depthFirstSearch(int u);

int main() {
	int i, j, n, u, k;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> ver[u].v[j];
		}
	}

	depthFirstSearch(1);

	for (i = 1; i <= n; i++) {
		cout << i << " " << ver[i].dt << " " << ver[i].ft << endl;
	}

	return 0;
}

void depthFirstSearch(int u) {

	if (ver[u].dt == 0) {
		int i = 0;

		ver[u].dt = curtime++;

		while (ver[u].v[i] != 0) {
			depthFirstSearch(ver[u].v[i]);
			i++;
		}

		ver[u].ft = curtime++;

		return;
	}
	return;
}

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

using namespace std;

int N,k[1000];
int v[1000][1000];
int found[1000] = {0},ended[1000] = {0};
int keep;
int checking=0;

void dfs(int cur);

int main() {
	cin >> N;
	for(int i=1;i<N+1;i++) {
		cin >> keep >> k[i];
		for(int j=1;j<k[i]+1;j++) {
			cin >> v[i][j];

		}
	}
	dfs(1);
	while(true) {
		//cout << "processing..." << endl;
		bool flag = false;
		int key = 1;
		for(int i=1;i<N+1;i++) {
			if(found[i] == 0) {
				flag = true;
				key = i;
				break;
			}
		}
		if(flag) {
			dfs(key);
		} else {
			break;
		}
	}
	
	
	for(int i=1;i<N+1;i++) {
		cout << i << " " << found[i] << " " << ended[i] << endl;
	}
	

}

void dfs(int cur) {
	//cout << "process ended" << endl;
	if(!found[cur]) {
		checking++;
		//cerr << "visiting: " << cur << " " << "time: " << checking << endl;
		found[cur] = checking;

	}
	for(int dst=1;dst<N+1;dst++) {
		bool flag = false;
		for(int i=1;i<k[cur]+1;i++) {
			if(v[cur][i] == dst) flag = true;
		}
		if((flag) && (dst != cur) && (!found[dst])) dfs(dst);
	}
	if(!ended[cur]) {
		checking++;
		//cerr << "ended: " << cur << " " << "time: " << checking << endl;
		ended[cur] = checking;
	}
}
/*
????????£????????????40?????????????????????????????????????????????????°?????????????????????????
*/

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<int> G[N];
int visited[N], checked[N];

int find_no_visited(int n) {
	int ret = -1;
	rep(i, n) {
		if (visited[i]) continue;
		ret = i;
		break;
	}
	return ret;
}

int find_no_visited(int n, int i) {
	int ret = -1;
	for (auto j : G[i]) {
		if (visited[j]) continue;
		ret = j;
		break;
	}
	return ret;
}

int main() {
	int n; cin >> n;
	rep(i, n) {
		int _, n2; cin >> _ >> n2;
		rep(j, n2) {
			int k; cin >> k; k--;
			G[i].push_back(k);
		}
	}
	rep(i, n) { visited[i] = 0; checked[i] = 0;}

	stack<int> S;
	int T = 1;
	S.push(0);
	visited[0] = T;
	while (true) {
		T++;
		if (S.empty()) {
			int i = find_no_visited(n);
			if (i != -1) {
				visited[i] = T;
				S.push(i);
				continue;
			}
			else
				break;
		}
		int i = find_no_visited(n, S.top());
		if (i != -1) {
			visited[i] = T;
			S.push(i);
		}
		else {
			checked[S.top()] = T;
			S.pop();
		}
	}
	rep(i, n) cout << i+1 << ' ' << visited[i] << ' ' << checked[i] << endl;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

ll d[100], f[100], now, cnt;
char flag[100];
vector<int> vec[100];

int dfs(int n) {
  if(f[n]) return 0;
  cnt++;
  d[n] = cnt;
  vector<int>::iterator it;
  for(it = vec[n].begin(); it != vec[n].end(); ++it) {
    if(!f[*it]) dfs(*it);
  }
  ++cnt;
  f[n] = cnt;
  return 0;
}

int main(void) {
  ll n;
  scanf("%d", &n);
  now = 0, cnt = 0;
  rep(i, n) flag[i] = 0;
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
    sort(vec[u].begin(), vec[u].end());
  }
  dfs(0);
  rep(i, n) printf("%d %lld %lld\n", i + 1, d[i], f[i]);
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
static const int N=100,WHITE=0,GRAY=1,BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u) {
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for (v=0; v<n; v++) {
    if (M[u][v]==0) {
      continue;
    }
    if(color[v]==WHITE) {
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs() {
  int u;
  for (u=0; u<n; u++) {
    color[u]=WHITE;
  }
  tt=0;
  for (u=0; u<n; u++) {
    if (color[u]==WHITE) {
      dfs_visit(u);
    }
  }
  for (u=0; u<n; u++) {
    cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl;
  }
}
int main() {
  int u,v,k,i,j;
  cin>>n;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      M[i][j]=0;
    }
  }
  for (i=0; i<n; i++) {
    cin>>u>>k;
    u--;
    for (j=0; j<k; j++) {
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = GRAY;
    d[u] = ++tt;
    for(v = 0; v < n;v++) {
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}
void dfs() {
    int u;
    for(u = 0;u < n;u++) {
        color[u] = WHITE;
    }
    tt = 0;
    for(u = 0;u < n;u++) {
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n;u++) {
        cout << u+1 <<" " <<d[u] << " " << f[u] << endl;
    }
}

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