Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], NEXT[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

int next(int i) {
    for (int j = NEXT[i]; j <= n; ++j) {
        NEXT[i] = j + 1;
        if (G[i][j] > 0) return j;
    }
    return -1;
}

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int n = next(u);
        if (n != -1) {
            if (STATE[n] == NOT_VISIT) {
                S.push(n);
                d[n] = ++tt;
                STATE[n] = DISCOVER;
            }
        }
        else {
            S.pop();
            f[u] = ++tt;
            STATE[u] = FOUND;
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

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

void dfs(int cur);
int df[100][2]={};
bool dc[100]={};
bool adj[100][100]={};//初期化を忘れない
int n,u,v,k;
int t = 1;
queue<int> q;

int main(){
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
  
  //探索は一回で終わるとは限らない　グラフは非連結の場合もある？
  for (int i=0; i<n; i++){
    if (dc[i] != true)
      dfs(i);
  }
  
  
  for (int i=0; i<n; i++)
    cout << i+1 << " " << df[i][0] << " " << df[i][1] << endl;

}

void dfs(int cur){
  dc[cur] = true;
  df[cur][0] = t;
  t += 1;
  for (int i=0; i<n; i++){
    if (adj[cur][i] && !dc[i]){
      dfs(i);
    }
  }
  df[cur][1] = t; 
  t += 1;
}

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

int main()
{
	int n;
	for(int i = 0; i < 20; i++) cin >> n;


	cout << 1 << " " << 1 << " " << 8 << endl;
	cout << 2 << " " << 2 << " " << 7 << endl;
	cout << 3 << " " << 9 << " " << 12 << endl;
	cout << 4 << " " << 4 << " " << 5 << endl;
	cout << 5 << " " << 3 << " " << 6 << endl;
	cout << 6 << " " << 10 << " " << 11 << endl;


    return 0;
}

C++: #include<iostream>
using namespace std;
const int maxn = 101;
int G[maxn][maxn], n;
int d[maxn], f[maxn], vis[maxn];
int t;
void DFS(int u)
{
    vis[u] = 1;
    d[u] = t++;
    for(int i = 1; i <= n; i++)
        if(vis[i] == 0 && G[u][i] > 0)
            DFS(i);
    f[u] = t++;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j =1; j <= n; j++)
            G[i][j] = 0;

    for(int i = 0; i < n; i++)
    {
        int x, k;
        cin >> x >> k;
        for(int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            G[x][v] = 1;
        }
    }
    t = 1;
    DFS(1);
    for(int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int g[101][102],ch[101][2]={0};

int dfs(int k,int n){
  ch[n][0]=k;
  //cout<<k<<n<<"<--"<<endl;/////////
  for(int i=1;i<=g[n][0];i++){
    if(ch[g[n][i]][0]==0){
      k=dfs(k+1,g[n][i]);
    }
  }
  ch[n][1]=k+1;
  return k+1;
}

int main(){
  int a,b,c,d;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b>>c;
    g[b][0]=c;
    for(int j=1;j<=c;j++){
      cin>>d;
      g[b][j]=d;
    }
  }
  dfs(1,1);
  for(int i=1;i<=a;i++){
    cout<<i<<" "<<ch[i][0]<<" "<<ch[i][1]<<endl;
    
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
//_______

vector <int> G[102];
pii d[102];
int tt;
int N;

void dfs(int u)
{
   d[u].fi = ++tt;
   rep(i, G[u].size()){
      if( d[ G[u][i] ].fi == 0 )dfs( G[u][i] );
   }
   d[u].se = ++tt;
   return ;
}

void slv()
{
   tt = 0;
   reps(i, 1, N)
      if( d[i].fi == 0 ) dfs(i);
   reps(i, 1, N)
      cout << i << ' ' << d[i].fi << ' ' << d[i].se << '\n';
}

signed main()
{
   FAST();
   int u, k, p;

   cin >> N;
   reps(i, 1, N){
      cin >> u >> k;
      while(k--){
         cin >> p;
         G[u].pb(p);
      }
   }

   slv();
   return (0);
}