Language: Java

public class Main {

	class Vertex {
		int id;
		int[] vertices;
		int visited = -1;
		int completed = -1;
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Vertex[] vertices = new Vertex[n];
		for (int i = 0; i < n; i++) {
			vertices[i] = new Vertex();
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			vertices[i].id = id;
			int cnt = Integer.parseInt(st.nextToken());
			vertices[i].vertices = new int[cnt];
			for (int j = 0; j < cnt; j++) {
				vertices[i].vertices[j] = Integer.parseInt(st.nextToken());
			}
		}
		reader.close();
		
		DFS(vertices, n);
		
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			System.out.println(vertex.id + " " + vertex.visited + " " + vertex.completed);
		}
	}

	private void DFS(Vertex[] vertices, int n) {
		int time = 0;
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			Stack<Integer> stack = new Stack<Integer>();
//			if (vertex.visited == -1) {
				stack.push(vertex.id);
//			}
			while (!stack.isEmpty()) {
				vertex = vertices[stack.peek()-1];
				if (vertex.visited == -1) {
					vertex.visited = ++time;
				}
				boolean allVisited = true;;
				for (int j = 0; j < vertex.vertices.length ; j++) {
					int childId = vertex.vertices[j];
					if (vertices[childId-1].visited == -1) {
						vertices[childId-1].visited = ++time;
						allVisited = false;
						stack.push(childId);
						break;
					}
				}
				if (allVisited) {
					vertex.completed = ++time;
					stack.pop();
				}
			}
		}
	}
}



Compiler output:
Main.java:10: error: cannot find symbol
	public static void main(String[] args) throws IOException {
	                                              ^
  symbol:   class IOException
  location: class Main
Main.java:14: error: cannot find symbol
	private void run() throws IOException {
	                          ^
  symbol:   class IOException
  location: class Main
Main.java:15: error: cannot find symbol
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		^
  symbol:   class BufferedReader
  location: class Main
Main.java:15: error: cannot find symbol
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		                            ^
  symbol:   class BufferedReader
  location: class Main
Main.java:15: error: cannot find symbol
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		                                               ^
  symbol:   class InputStreamReader
  location: class Main
Main.java:20: error: cannot find symbol
			StringTokenizer st = new StringTokenizer(reader.readLine());
			^
  symbol:   class StringTokenizer
  location: class Main
Main.java:20: error: cannot find symbol
			StringTokenizer st = new StringTokenizer(reader.readLine());
			                         ^
  symbol:   class StringTokenizer
  location: class Main
Main.java:43: error: cannot find symbol
			Stack<Integer> stack = new Stack<Integer>();
			^
  symbol:   class Stack
  location: class Main
Main.java:43: error: cannot find symbol
			Stack<Integer> stack = new Stack<Integer>();
			                           ^
  symbol:   class Stack
  location: class Main
9 errors