Submission #1009227

# Submission time Handle Problem Language Result Execution time Memory
1009227 2024-06-27T10:11:05 Z phoenix Friend (IOI14_friend) C++17
69 / 100
17 ms 1472 KB
#include "friend.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1000;

mt19937 rnd(228);

vector<int> g[N];
int back[N];
int vis[N];

bool dfs(int s, int c) {
	vis[s] = c;	
	for (int to : g[s]) {
		if (back[to] == -1 || (vis[back[to]] != c && dfs(back[to], c))) {
			back[to] = s;
			return true;
		}
	}
	return false;
}

int findSample(int n, int confidence[], int host[], int protocol[]){
	int pro_min = *min_element(protocol + 1, protocol + n);
	int pro_max = *max_element(protocol + 1, protocol + n); 
	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;
	}
	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]);
	} 
	
	if (pro_min >= 0 && pro_max <= 1) {
		int color[n] = {};
		for (int i = 1; i < n; i++) {
			if (protocol[i] == 0) {
				color[i] = !color[host[i]];
				g[host[i]].push_back(i);
				g[i].push_back(host[i]);
			} else {
				color[i] = color[host[i]];
				g[i] = g[host[i]];
				for (int c : g[i]) 
					g[c].push_back(i);
			}
		}	
		for (int i = 0; i < n; i++)
			back[i] = -1;
		vector<int> st;
		for (int i = 0; i < n; i++) if (!color[i])
			st.push_back(i);
		shuffle(st.begin(), st.end(), rnd);
		
		int verse = 0, M = 0;
		for (int v : st) {
			M += dfs(v, ++verse);
		}
		return n - M;		
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 17 ms 1472 KB Output isn't correct
13 Halted 0 ms 0 KB -