Submission #66578

#TimeUsernameProblemLanguageResultExecution timeMemory
66578aquablitz11Friend (IOI14_friend)C++14
38 / 100
50 ms7488 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; const int N = 1010; int n, *conf; bool act[N]; vector<int> G[N]; int solve(int u) { if (u == n) return 0; bool can = true; for (auto v : G[u]) if (act[v]) can = false; int ans = 0; if (can) { act[u] = true; ans = max(ans, conf[u]+solve(u+1)); } act[u] = false; ans = max(ans, solve(u+1)); return ans; } int dp[N][2]; void dfs(int u, int p) { dp[u][1] = conf[u]; for (auto v : G[u]) if (v != p) { dfs(v, u); dp[u][0] += max(dp[v][0], dp[v][1]); dp[u][1] += dp[v][0]; } } int findSample(int n, int confidence[], int host[], int protocol[]) { if (n > 100000) return -1; ::n = n; conf = confidence; for (int i = 1; i < n; ++i) { if (protocol[i] != 1) { G[i].push_back(host[i]); G[host[i]].push_back(i); } if (protocol[i] != 0) { for (auto v : G[host[i]]) { G[i].push_back(v); G[v].push_back(i); } } } if (n <= 10) return solve(0); if (protocol[1] == 1) { int sum = 0; for (int i = 0; i < n; ++i) sum += conf[i]; return sum; } if (protocol[1] == 2) { int mx = 0; for (int i = 0; i < n; ++i) mx = max(mx, conf[i]); return mx; } dfs(0, 0); return max(dp[0][0], dp[0][1]); }
#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...