Submission #592090

#TimeUsernameProblemLanguageResultExecution timeMemory
592090HanksburgerFriend (IOI14_friend)C++17
8 / 100
7 ms9900 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005], adj2[100005], vec; bool grp[100005], ok[100005], ok2[100005]; queue<pair<int, bool> > q; int findSample(int n, int c[], int h[], int p[]) { for (int i=1; i<n; i++) { if (!p[i]) { adj[i].push_back(h[i]); adj[h[i]].push_back(i); } else if (p[i]==1) { if (adj[h[i]].size()) { adj[i].push_back(adj[h[i]][0]); adj[adj[h[i]][0]].push_back(i); } } else { adj[i].push_back(adj[h[i]][0]); adj[adj[h[i]][0]].push_back(i); adj2[i].push_back(h[i]); adj2[h[i]].push_back(i); } } int ans=0; for (int i=0; i<n; i++) { if (!ok[i]) { vec.clear(); vec.push_back(i); q.push({i, 0}); ok[i]=1; while (!q.empty()) { int u=q.front().first, g=q.front().second; q.pop(); for (int v:adj[u]) { if (!ok[v]) { grp[v]=!grp[u]; vec.push_back(v); q.push({v, grp[v]}); ok[v]=1; } } } int sum[2]={}; for (int j:vec) { if (!ok2[j]) { int cnt[2]={c[j], 0}; q.push({j, 0}); ok2[j]=1; while (!q.empty()) { int u=q.front().first, g=q.front().second; q.pop(); for (int v:adj2[u]) { if (!ok2[v]) { cnt[!g]+=c[v]; q.push({v, !g}); ok2[v]=1; } } } sum[grp[j]]+=max(cnt[0], cnt[1]); } } ans+=max(sum[0], sum[1]); } } return ans; }

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:42:40: warning: unused variable 'g' [-Wunused-variable]
   42 |                 int u=q.front().first, g=q.front().second;
      |                                        ^
#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...