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
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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>
#define Gray 0
#define White 1
#define Black 2
int time;
int d[101],f[101],color[101],Adj[101][101];  
int n;

void DFS_Visit(int u){
  int i;  
  color[u]=Gray;
  d[u]=++time;
  for(i=1;i<=n;i++){
    if(color[i]==White && Adj[u][i]==1) DFS_Visit(i);
  }
  color[u]=Black;
  f[u]=++time;
}

void DFS(){
  int i;
  for(i=1;i<=n;i++){
    color[i]=White;
  }
  time=0;
  for(i=1;i<=n;i++){
    if(color[i]==White) DFS_Visit(i);
}
}

main(){
  
  int k,i,j,t,g;

  scanf("%d",&n);
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	Adj[i][j]=0;
      }
    } 
    
    for(i=1;i<=n;i++){
      scanf("%d",&g);    
      scanf("%d",&k);
      for(j=1;j<=k;j++){
	scanf("%d",&t);
	Adj[g][t]=1;   
      }
    } DFS();
    
    for(i=1;i<=n;i++){
   
      printf("%d %d %d\n",i,d[i],f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> first_order; // 行きがけ順
vector<int> last_order; // 帰りがけ順
void dfs(const vector<vector<int>> &G,int v,int& ptr){
  first_order[v] = ptr++;

  // vを訪問済みにする
  seen[v] = true;

  // vから行ける各頂点next_vについて
  for(auto next_v:G[v]){
    if(seen[next_v]) continue;
    dfs(G,next_v,ptr);
  }

  last_order[v] = ptr++;
}

int main(){
  //頂点数
  int n;
  cin >> n;

  Graph G(n+1);
  //頂点番号、隣接頂点数、隣接頂点番号
  for(int i=1;i<=n;i++){
    int u,k;
    cin >> u >> k;
    for(int j=0;j<k;j++){
      int v;
      cin >> v;
      G[u].push_back(v);
    }
  }

  seen.assign(n+1,false);
  first_order.resize(n+1);
  last_order.resize(n+1);
  int ptr = 1;
  for(int i=1;i<=n;i++){
    if(seen[i]) continue;
    dfs(G,i,ptr);
  }

  // 各頂点vの行きがけ順、帰りがけ順を出力
  for(int v = 1;v<=n;v++){
    cout << v << " " << first_order[v] << " " << last_order[v] << endl;
  }
}

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

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


int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}


void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GREY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GREY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}


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

	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k, v;

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

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

	dfs();

	return 0;
}

C++: using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Node
    {
        public List <Edge> Edges;
        public int Dist;
        public int No;
        public bool Visited;
        public int Start;
        public int End;

        public Node(int no)
        {
            this.No = no;
            Dist = int.MaxValue;
            Edges = new List<Edge>();
            Visited = false;
        }
    }

    internal class Edge
    {
        public int From;
        public int To;
        public int Cost;
       

        public Edge(int fr, int to, int cost = 0)
        {
            From = fr;
            To = to;
            Cost = cost;
        }

    }

    internal class Graph
    {
        public List<Node> Nodes;

        public Node this[int i]
        {
            set { Nodes[i] = value; }
            get { return Nodes[i]; }
        }

        public Graph(int N)
        {
            Nodes = new List<Node>();
            for (int i = 0; i < N; i++)
            {
                Nodes.Add(new Node(i));
            }
        }

    }

    internal class Solution
    {
        public int N;
        public Graph G;
        public int T;

        public void Run()
        {
            N = Input.ReadInt();
            G = new Graph(N);
            
            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadIntArray();
                var o = line[1];
                for (int j = 0; j < o; j++)
                {
                    int fr = i;
                    int to = line[2 + j] - 1;
                    G[i].Edges.Add(new Edge(fr, to));
                }
            }

            RunGraph();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("{0} {1} {2}", i, G[i].Start, G[i].End);
            }
        }

        public void RunGraph()
        {
            T = 0;
            for (int i = 0; i < N; i++)
                DFS(i);

        }

        public void DFS(int i)
        {
            if (G[i].Visited) return;
            T++;
            G[i].Start = T;
            G[i].Visited = true;
            foreach (var e in G[i].Edges)
            {
                DFS(e.To);
            }

            T++;
            G[i].End = T;
        }

    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}