이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |