Submission #1510692


Source Code Expand

import java.util.*;
 
/**
 * http://abc002.contest.atcoder.jp/tasks/abc002_4
 */
public class Main {
 
	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean graph[][] = new boolean[N][N];
		for(int i=0; i<M; i++){
			int n1 = sc.nextInt();
			int n2 = sc.nextInt();
			graph[n1-1][n2-1] = true;
			graph[n2-1][n1-1] = true;
		}
		sc.close();
	
		System.out.println(maxClusterDfs(graph));	
	}

	public static int maxCluster(boolean[][] graph){
		int nodeSize = graph.length;
		
		int result = 0;
		for(int bmask=1; bmask < (1<<nodeSize); ++bmask){
			List<Integer> candidate = new ArrayList<>();
			int tmp = bmask;
			int shift=0;
			while(tmp != 0){
				if((tmp&1)!=0)candidate.add(shift);
				tmp>>=1;
				++shift;
			}
			if(isFullyConnected(graph, candidate))result=Math.max(result,candidate.size());
		}
		return result;
	}

	public static boolean isFullyConnected(boolean[][] graph, List<Integer>  nodeList){
		for(int i=0; i < nodeList.size(); ++i){
			for(int j=i+1; j < nodeList.size(); ++j){
				if(!graph[nodeList.get(i)][nodeList.get(j)])return false;
			}
		}
		return true;
	}
	
	public static int maxClusterDfs(boolean[][] graph){
		int nodeSize = graph.length;
		Set<Integer> visited = new HashSet<>();
		int result = 0;
		
		List<Map<String, Integer>> memoization = new ArrayList<Map<String,Integer>>();
		for(int start = 0; start < nodeSize; ++start){
			visited.add(start);
			result = Math.max(1 + dfs(graph, start, visited, memoization), result);
			visited.remove(start);
		}
		return result;
	}
	
	public static boolean isFullyConnected(boolean[][] graph, Set<Integer> visited, int newNode){
		for(int i : visited){
			if(!graph[i][newNode]) return false;
		}
		return true;
	}
	
	public static int dfs(boolean[][] graph, int currentNode, Set<Integer> visited, List<Map<String, Integer>> memoization){
		if(memoization.get(0).containsKey(visited.toString()) > 0) return  0;
		int result = 0;
		for(int nextNode = 0; nextNode < graph.length; ++nextNode){
			if(!graph[currentNode][nextNode])continue;
			if(visited.contains(nextNode))continue;
			if(isFullyConnected(graph, visited, nextNode)){
				visited.add(nextNode);
				result = Math.max(result, 1 + dfs(graph, nextNode, visited, memoization));
				visited.remove(nextNode);
			}
		}
		memoization.get(currentNode).put(visited.toString(), result);
		return result;
	}
}


Submission Info

Submission Time
Task D - 派閥
User hi_viv
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2527 Byte
Status CE

Compile Error

./Main.java:74: error: bad operand types for binary operator '>'
		if(memoization.get(0).containsKey(visited.toString()) > 0) return  0;
		                                                      ^
  first type:  boolean
  second type: int
1 error