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 "friend.h"
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N=1009;
vector<int>v[N];
int vis[N],a[N];int re=0,al=0;
void dfs(int x,int z)
{
if(vis[x]!=-1&&vis[x]!=z)while(1)re++;
if(vis[x]!=-1)return;
vis[x]=z;if(z)re++;al++;
for(auto it:v[x])
{
if(vis[it]!=-1)continue;
dfs(it,1-z);
}
}
int findSample(int n,int c[],int h[],int p[]){
memset(vis,-1,sizeof vis);
for(int i=1;i<n;i++)
{
if(p[i]==0){
v[h[i]].pb(i);
v[i].pb(h[i]);}
else {
for(auto it:v[h[i]]){
v[i].pb(it);
v[it].pb(i);
}
}
}
int mx=0;
for(int i=0;i<n;i++)a[i]=c[i];
for(int i=0;i<n;i++)
{
if(vis[i]!=-1)continue;
re=0;al=0;
dfs(i,0);
mx+=max(re,al-re);
}
return mx;
}
/*
5
1 100 1 1 100
0 0
0 0
1 1
2 2
*/
# | 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... |