제출 #587056

#제출 시각아이디문제언어결과실행 시간메모리
587056Jomnoi친구 (IOI14_friend)C++17
16 / 100
27 ms4204 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; const int MAX_N = 1e5 + 5; int N, C[MAX_N]; int dp[MAX_N][2]; vector <int> graph[MAX_N]; void dfs(int u) { dp[u][1] = C[u]; for(auto v : graph[u]) { dfs(v); dp[u][0] += max(dp[v][0], dp[v][1]); } for(auto v : graph[u]) { dp[u][1] = max(dp[u][1], dp[u][0] - max(dp[v][0], dp[v][1]) + dp[v][0] + C[u]); } } // Find out best sample int findSample(int n, int confidence[], int host[], int protocol[]){ N = n; int cnt[3] = {}; for(int i = 0; i < N; i++) { C[i] = confidence[i]; } for(int i = 1; i < N; i++) { cnt[protocol[i]]++; } int ans = 0; if(n <= 10) { for(int i = 1; i < N; i++) { vector <int> need; if(protocol[i] == 0) { need.push_back(host[i]); } else if(protocol[i] == 1) { for(auto v : graph[host[i]]) { need.push_back(v); } } else if(protocol[i] == 2) { need.push_back(i); for(auto v : graph[host[i]]) { need.push_back(v); } } for(auto v : need) { graph[i].push_back(v); graph[v].push_back(i); } } for(int mask = 0; mask < (1<<N); mask++) { set <int> consider; int sum = 0; for(int i = 0; i < N; i++) { if(mask & (1<<i)) { sum += C[i]; consider.insert(i); } } for(auto u : consider) { for(auto v : graph[u]) { if(consider.count(v)) { sum = 0; } } } ans = max(ans, sum); } } else if(cnt[0] == N - 1) { for(int i = 1; i < N; i++) { graph[host[i]].push_back(i); } dfs(0); ans = max(dp[0][0], dp[0][1]); } else if(cnt[1] == N - 1) { for(int i = 0; i < N; i++) { ans += confidence[i]; } } else if(cnt[2] == N - 1) { for(int i = 0; i < N; i++) { ans = max(ans, confidence[i]); } } else { // do something } return ans; }
#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...