Submission #1009216

#TimeUsernameProblemLanguageResultExecution timeMemory
1009216phoenixFriend (IOI14_friend)C++17
0 / 100
1 ms348 KiB
#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 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 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...