Submission #363575

#TimeUsernameProblemLanguageResultExecution timeMemory
363575silverfishFriend (IOI14_friend)C++14
35 / 100
2 ms492 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int N = 1e3; vector<int> adj[N]; long long dp[N][2]; int vis[N]; void dfs(int u, int p, int *conf){ for(int v : adj[u]){ if(v != p) dfs(v, u, conf); } for(int v : adj[u]){ if(v != p){ dp[u][0] += max(dp[v][1], dp[v][0]); dp[u][1] += dp[v][0]; } } dp[u][1] += 1LL*conf[u]; } int findSample(int n, int conf[],int host[],int protocol[]){ bool subtask2 = 1, subtask3 = 1, subtask4 = 1, subtask5 = 1; for(int i = 1; i < n; ++i){ if(protocol[i] != 1) subtask2 = 0; if(protocol[i] != 2) subtask3 = 0; if(protocol[i] != 0) subtask4 = 0; if(conf[i] != 1) subtask5 = 0; } if(subtask2){ long long ans = 0; for(int i = 0; i < n; ++i) ans += 1LL*conf[i]; return ans; } if(subtask3){ return *max_element(conf, conf+n); } if(subtask4){ //build tree for(int i = 1; i < n; ++i){ adj[host[i]].push_back(i); adj[i].push_back(host[i]); } dfs(0, 0, conf); return max(dp[0][1], dp[0][0]); } if(subtask5){ for(int i = 1; i < n; ++i){ if(protocol[i] == 0){ adj[host[i]].push_back(i); adj[i].push_back(host[i]); }else{ for(int j : adj[host[i]]){ adj[i].push_back(j); adj[j].push_back(i); } } } queue<array<int,2>> q; memset(vis, 0, sizeof vis); long long ans = 0; for(int i = 0; i < n; ++i){ if(vis[i]) continue; array<long long,2> curans = {0LL, 0LL}; q.push({i, 0}); // node, depth vis[i] = 1; while(q.size()){ auto x = q.front(); q.pop(); int u = x[0], d = x[1]; ++curans[d%2]; for(int v : adj[u]){ if(!vis[v]){ vis[v] = 1; q.push({v, d+1}); } } } ans += max(curans[0], curans[1]); } return ans; } return -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...