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 <iostream>
#include <vector>

using namespace std;

int tim = 0;
vector<vector<int>> to;
vector<bool> reached;
vector<int> d;
vector<int> f;



void dfs(int point);

int main()
{
    int n;
    cin >> n;
    to.resize(n+1);
    for(int i = 1; i <= n; i++){
        int m;
        cin >> m;
        cin >> m;
        to[i].resize(m);
        for(int j = 0; j < m; j++){
            cin >> to[i][j];
        }
    }
    
    reached.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);

    for(int i = 1; i <=n; i++){
        if(!reached[i]){
            dfs(i);
        }
    }

    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

void dfs(int point)
{
    tim++;
    reached[point] = true;
    d[point] = tim;

    for(int i = 0; i < to[point].size(); i++){
        if(!reached[to[point][i]]){
            dfs(to[point][i]);
        }
    }
    tim++;
    f[point] = tim;    

}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

void dfs(const Graph &g, size_t v, int &t, vector<int> &d, vector<int> &f) {
    d[v] = t;
    for (const Edge &e: g[v])
        if (!d[e.dst])
            dfs(g, e.dst, ++t, d, f);

    f[v] = ++t;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t k;
        scanf("%*d %zu", &k);
        for (size_t j=0; j<k; ++j) {
            size_t v;
            scanf("%zu", &v);
            --v;

            connect(g, i, v);
        }
    }

    vector<int> d(n), f(n);
    int t=1;
    for (size_t v=0; v<n; ++v)
        if (!d[v])
            dfs(g, v, t, d, f);

    for (size_t i=0; i<n; ++i)
        printf("%zu %d %d\n", i+1, d[i], f[i]);

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


vector<vector< int> > tstamp;
int n;
vector<vector<int> > G;
int ttime=0;

void tansaku(int i){
  if (tstamp[i][1]) return;
  ttime++;
  if (!tstamp[i][0]) tstamp[i][0] = ttime;
  for (int j=0;j<n;j++)
    if(G[i][j]) tansaku(j);
  tstamp[i][1] = ++ttime;
}




int main(){
  cin >> n;
  G.assign(n, vector<int>(n,0));
  for (int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for (int j=0;j<k;j++){
      int v;
      cin >> v;
      G[u-1][v-1] = 1;
    }
  }
  tstamp.assign(n,vector<int>(2,0));
  tansaku(0);

  for(int id=0;id<n;id++){
    cout << id+1 << " " << tstamp[id][0] << " " << tstamp[id][1] << endl;
  }
}

C++: #include<iostream>
#include<vector>
#define SIZE 1000000
using namespace std;

struct Stack{
  int line[SIZE];
  int top;
  void init(){
    top = 0;
  }
  bool empty(){
    return top==0;
  }
  void push(int x){
    line[top]=x;
    top ++;
  }
  int pop(){
    if(empty()) return -1;
    top--;
    return line[top];
  }
};
struct Node
{
  vector<int> toList;
  int dt;
  int ft;
};

Stack stack; 
int t; //time

void init(vector<Node>& nodes)
{
  t=0;
  stack.init();
  stack.push(0);
  for(int i=0;i<nodes.size();i++){
    nodes[i].ft=-1;
    nodes[i].dt=-1;
  }
}
void print(vector<Node> nodes)
{
  int n=nodes.size();
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<nodes[i].ft<<" "<<nodes[i].dt<<endl;
  }
}
void dfs(vector<Node>& nodes)
{ 
  int idx=stack.pop();
  //cout<<idx+1<<":";
  if(idx>=0){
    if(nodes[idx].ft<0){
      //cout<<" find";
      t++;
      nodes[idx].ft=t;
    }
    if(nodes[idx].toList.size()<=0){
      //cout<<" toList.size==0"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
    int count=0;
    for(int i=0;i<nodes[idx].toList.size();i++){
      if(nodes[nodes[idx].toList[i]].dt<0){
	//cout<<" jumpto "<<i+1<<endl;
	count++;
	stack.push(idx);
	stack.push(nodes[idx].toList[i]);
	dfs(nodes);
      }
    }
    if(count==0 && nodes[idx].dt<0){
      //cout<<" finish"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
  }else{
    //cout<<"finish dfs"<<endl;
  }
}

int main()
{
  int n,u,k;
  cin>>n;
  vector<Node> nodes(n);
  for(int i=0;i<n;i++){
    cin>>u>>k;
    nodes[i].toList.resize(0);
    for(int j=0;j<k;j++){
      int tmp;
      cin>>tmp;
      nodes[i].toList.push_back(tmp-1);
    }
  }
  init(nodes);
  //print(nodes);

  dfs(nodes);
  print(nodes);
  return 0;
}

C++: def main():
    n = input()
    A = []
    s = []
    B = [[0,0] for i in xrange(n)]
    for i in xrange(n):
        A.append(map(int,raw_input().split()))

    color = [-1]*n
    d = [0]*n
    f = [0]*n
    
    dfs(0,0,color,d,f,A,n)

    for i in xrange(n):
        print i+1, d[i], f[i]


def dfs(u,t,color,d,f,A,n):
    t += 1
    color[u] = 0
    d[u] = t
    for i in A[u][2:]:
        if (color[i-1] == -1):
            t = dfs(i-1,t,color,d,f,A,n)
    color[u] = 1
    t += 1
    f[u] = t
    return t

if __name__ == '__main__':
    main()