Submission #1510711


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<Integer, Integer>> memoization = new ArrayList<Map<Integer,Integer>>();
		for(int i=0; i < nodeSize; ++i) memoization.add(new HashMap<Integer,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<Integer, Integer>> memoization){
		int memoizationKey = 0;
		for(Integer v : visited) memoizationKey = (memoizationkey | (1 << v));
		if(memoization.get(currentNode).containsKey(memoizationKey)) return memoization.get(currentNode).get(memoizationKey);
		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(memoizationKey, result);
		return result;
	}
}


Submission Info

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

Compile Error

./Main.java:76: error: cannot find symbol
		for(Integer v : visited) memoizationKey = (memoizationkey | (1 << v));
		                                           ^
  symbol:   variable memoizationkey
  location: class Main
1 error