Submission #1009117

#TimeUsernameProblemLanguageResultExecution timeMemory
1009117phoenix친구 (IOI14_friend)C++17
46 / 100
15 ms2684 KiB
#include "friend.h"
#include <bits/stdc++.h>

using namespace std;

int findSample(int n, int confidence[], int host[], int protocol[]){
	if (n <= 10) {
		bool edge[n][n] = {};
		for (int i = 1; i < n; i++) {
			if (~protocol[i] & 1) {
				edge[host[i]][i] = edge[i][host[i]] = true;
			} 
			if (protocol[i]) {
				for (int j = 0; j < i; j++) if (edge[host[i]][j])
					edge[j][i] = edge[i][j] = true;
			}
		}
		int ans = 0;
		for (int msk = 0; msk < (1 << n); msk++) {
			bool check = false;
			for (int i = 0; i < n; i++) {
				if (~msk >> i & 1) continue;
				for (int j = 0; j < n; j++) {
					if (~msk >> j & 1) continue;
					check |= edge[i][j];
				}
			}
			if (check) continue;
			int s = 0;
			for (int i = 0; i < n; i++) if (msk >> i & 1)
				s += confidence[i];
			ans = max(ans, s);
		}
		return ans;
	}
	int pro_min = *min_element(protocol + 1, protocol + n);
	int pro_max = *max_element(protocol + 1, protocol + n); 
	if (pro_min == 2 && pro_max == 2) {
		return *max_element(confidence, confidence + n);
	}
	if (pro_min == 1 && pro_max == 1) {
		bool color[n] = {};
		color[0] = false;
		for (int i = 1; i < n; i++) 
			color[i] = color[host[i]];
		int ans[2] = {};
		for (int i = 0; i < n; i++) 
			ans[color[i]] += confidence[i];
		return max(ans[0], ans[1]);
	}
	if (pro_min == 0 && pro_max == 0) {
		vector<vector<int>> g(n);
		for (int i = 1; i < n; i++) {
			g[host[i]].push_back(i);
		}
		int dp[n][2] = {};
		function<void(int)> dfs = [&](int s) {
			dp[s][0] = 0;
			dp[s][1] = confidence[s];
			for (int to : g[s]) {
				dfs(to);
				dp[s][0] += max(dp[to][0], dp[to][1]);
				dp[s][1] += dp[to][0];
			}
		};
		dfs(0);
		return max(dp[0][0], dp[0][1]);
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...