This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool grp[100005], ok[100005];
queue<pair<long long, bool> > q;
vector<long long> adj[100005];
int findSample(int n, int c[], int h[], int p[])
{
for (long long i=1; i<n; i++)
{
if (!p[i])
grp[i]=!grp[h[i]];
else if (p[i]==1)
grp[i]=grp[h[i]];
else
{
grp[i]=grp[h[i]];
adj[i].push_back(h[i]);
adj[h[i]].push_back(i);
}
}
long long ans[2]={};
for (long long i=0; i<n; i++)
{
if (!ok[i])
{
long long cnt[2]={c[i], 0};
q.push({i, 0});
ok[i]=1;
while (!q.empty())
{
long long u=q.front().first, g=q.front().second;
q.pop();
for (long long v:adj[u])
{
if (!ok[v])
{
cnt[!g]+=c[v];
q.push({v, !g});
ok[v]=1;
}
}
}
ans[grp[i]]+=max(cnt[0], cnt[1]);
}
}
return max(ans[0], ans[1]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |