public boolean canFinish(int numCourses, int[][] prerequisites) {
		if (prerequisites == null || prerequisites.length == 0)
			return true;
		HashSet<Integer>[] graph = new HashSet[numCourses]; // adjcent list
		for (int i = 0; i < numCourses; i++)
			graph[i] = new HashSet<Integer>();
		for (int i = 0; i < prerequisites.length; i++)
			graph[prerequisites[i][1]].add(prerequisites[i][0]);

		boolean visited[] = new boolean[numCourses];
		boolean visiting[] = new boolean[numCourses];
		for (int i = 0; i < numCourses; i++) {
			if (!visited[i]) {
				if (!(dfs(graph, visited, visiting, i)))
					return false;
			}
		}

		return true;
	}