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>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define F first
#define S second
#define P pair
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
V<int>adj[(int)2000];
ll dp[1001][2];
int conf[1001];
void dfs(int n,int p){
if(adj[n].size()==1 && n!=0){
dp[n][0]=0;
dp[n][1]=conf[n];
return;
}
for(auto u:adj[n]){
if(u==p)continue;
dfs(u,n);
}
dp[n][0]=0;
dp[n][1]=conf[n];
for(auto u:adj[n]){
dp[n][1]+=dp[u][0];
dp[n][0]+=max(dp[u][0],dp[u][1]);
}
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i=1;i<n;i++) {
if (protocol[i] == 0) {
adj[host[i]].pb(i);
adj[i].pb(host[i]);
}
}
for(int i=0;i<n;i++)
conf[i]=confidence[i];
dfs(0,-1);
return (int)max(dp[0][1],dp[0][0]);
}
# | 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... |