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<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int MAXN=100010;
int n, dp[2][MAXN], conf[MAXN];
vector<int> g[MAXN];
void dfs(int v, int p){
dp[1][v]=conf[v];
for(int to:g[v]) if(to!=p) {
dfs(to, v);
dp[1][v]+=dp[0][to];
dp[0][v]+=dp[1][to];
}
dp[1][v]=max(dp[0][v], dp[1][v]);
}
int solve0(int confidence[], int host[]){
forsn(i, 1, n) g[i].PB(host[i]), g[host[i]].PB(i);
dfs(0, 0);
return dp[1][0];
}
int solve1(int confidence[], int host[]){
int sum=0;
forn(i, n) sum+=confidence[i];
return sum;
}
int solve2(int confidence[], int host[]){
int mx=-1;
forn(i, n) mx=max(mx, confidence[i]);
return mx;
}
int solveTask(int task, int confidence[], int host[]){
if(task==0) return solve0(confidence, host);
else if(task==1) return solve1(confidence, host);
else if(task==2) return solve2(confidence, host);
}
// Find out best sample
int findSample(int N, int confidence[], int host[], int protocol[]){
n=N;
forn(i, n) conf[i]=confidence[i];
bool eq=true;
forsn(i, 1, n-1) eq&=protocol[i]==protocol[i+1];
if(eq) return solveTask(protocol[1], confidence, host);
return 0;
}
Compilation message (stderr)
friend.cpp: In function 'int solveTask(int, int*, int*)':
friend.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
45 | }
| ^
# | 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... |