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;
#define F first
#define S second
typedef pair<int, int> ii;
#define FORi(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define FOR(i,n) FORi(i,0,n)
#include "friend.h"
typedef vector<int> vi;
// Find out best sample
vector<vi> adj;
vi vis;
int a[10000];
int dp[100000][2];
int dfs(int s, int p=-1, int cp=0){
if(dp[s][cp]) return dp[s][cp];
vis[s] = true;
int ans1 = 0;
int ans2=0;
if(cp){
for(auto v : adj[s]) if(v!=p) ans1+=dfs(v, s, 0);
}
else{
for(auto v : adj[s]) if(v!=p) ans1+=dfs(v, s, 0);
ans2 = a[s];
for(auto v : adj[s]) if(v!=p) ans2+=dfs(v, s, 1);
}
//cout<<s<<" "<<cp<<" "<<ans1<<" "<<ans2<<endl;
dp[s][cp] = max(ans1, ans2);
return max(ans1, ans2);
}
int findSample(int n,int confidence[],int host[],int protocol[]){
int ans=0;
if(protocol[1]==1) FOR(i,n) ans+=confidence[i];
else if(protocol[1]==2) FOR(i,n) ans=max(ans, confidence[i]);
else{
FOR(i,n) a[i] = confidence[i];
adj.assign(n+1, vi());
vis.assign(n+1, false);
FORi(i,1,n){
adj[host[i]].push_back(i);
adj[i].push_back(host[i]);
}
FOR(i,n) if(!vis[i]) ans+=dfs(i);
}
return ans;
}
# | 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... |