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>
using namespace std;
const int N = 1e3;
vector<int> adj[N];
long long dp[N][2];
int vis[N], side[N], friends[N];
void dfs(int u, int p, int *conf){
for(int v : adj[u]){
if(v != p) dfs(v, u, conf);
}
for(int v : adj[u]){
if(v != p){
dp[u][0] += max(dp[v][1], dp[v][0]);
dp[u][1] += dp[v][0];
}
}
dp[u][1] += 1LL*conf[u];
}
int findSample(int n, int conf[],int host[],int protocol[]){
bool subtask2 = 1, subtask3 = 1, subtask4 = 1, subtask5 = 1;
if(conf[0] != 1) subtask5 = 0;
for(int i = 1; i < n; ++i){
if(protocol[i] != 1) subtask2 = 0;
if(protocol[i] != 2) subtask3 = 0;
if(protocol[i] != 0) subtask4 = 0;
if(conf[i] != 1) subtask5 = 0;
}
if(subtask5){
side[0] = 0;
array<long long,2> ans = {0, 0};
++ans[side[0]];
friends[0] = 0;
for(int i = 1; i < n; ++i){
if(protocol[i] == 0){
side[i] = !side[host[i]];
++ans[side[i]];
friends[i] = 1;
++friends[host[i]];
}else{
side[i] = side[host[i]];
friends[i] = friends[host[i]];
if(friends[i] == 0) ++ans[!side[i]];
++ans[side[i]];
}
}
if(friends[0] == 0) ++ans[!side[0]];
return max(ans[0], ans[1]);
}
if(subtask2){
long long ans = 0;
for(int i = 0; i < n; ++i) ans += 1LL*conf[i];
return ans;
}
if(subtask3){
assert(0);
return *max_element(conf, conf+n);
}
if(subtask4){
assert(0);
//build tree
for(int i = 1; i < n; ++i){
adj[host[i]].push_back(i);
adj[i].push_back(host[i]);
}
dfs(0, 0, conf);
return max(dp[0][1], dp[0][0]);
}
return -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... |