Submission #145479

#TimeUsernameProblemLanguageResultExecution timeMemory
145479TAMREFFriend (IOI14_friend)C++11
27 / 100
39 ms4984 KiB
#include "friend.h" #include <bits/stdc++.h> #define all(v) (v).begin(),(v).end() using namespace std; int n; vector<int> c, h, p; int bf(){ vector<vector<int>> e(n, vector<int>(n)); for(int i = 1; i < n; i++){ switch(p[i]){ case 0: e[h[i]][i] = e[i][h[i]] = 1; break; case 1: for(int j = 0; j < i; j++){ if(e[h[i]][j]) e[i][j] = e[j][i] = 1; } break; case 2: e[h[i]][i] = e[i][h[i]] = 1; for(int j = 0; j < i; j++){ if(e[h[i]][j]) e[i][j] = e[j][i] = 1; } break; } } int ans = 0; for(int b = 0; b < (1<<n); b++){ int lans = 0; for(int i = 0; i < n; i++){ if(~b >> i & 1) continue; for(int j = 0; j < n; j++){ if(~b >> j & 1) continue; if(e[i][j]) goto FAIL; } } for(int i = 0; i < n; i++){ if(b >> i & 1){ lans += c[i]; } } ans = max(ans, lans); FAIL: continue; } return ans; } vector<int> G[100005]; int dp[100005][2]; void dfs(int x){ dp[x][1] = c[x]; for(int u : G[x]){ dfs(u); dp[x][0] += dp[u][1]; dp[x][1] += dp[u][0]; } } int tree_dp(){ for(int i = 1; i < n; i++) G[h[i]].push_back(i); dfs(0); return max(dp[0][0], dp[0][1]); } int findSample(int N, int C[], int H[], int P[]){ n = N; c = vector<int>(C,C+n); h = vector<int>(H,H+n); p = vector<int>(P,P+n); int uq; p[0] = p[1]; if((uq = *min_element(all(p))) == *max_element(all(p))){ switch(uq){ case 0: return tree_dp(); case 1: return accumulate(all(c), 0); case 2: return *max_element(all(c)); } } if(n <= 10) return bf(); 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...