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 <vector>
#include <iostream>
// Find out best sample
using namespace std;
const int nmax=100005;
vector<int> v[nmax],ad[nmax],inloc[nmax];
int sum[nmax][2],best[nmax][2];
int a[nmax],val[nmax];
int nr,p,tip;
void dfs(int x)
{
for(int i=0;i<v[x].size();i++)
dfs(v[x][i]);
nr=0;
for(int i=0;i<v[x].size();i++)
{
a[++nr]=v[x][i];
sum[nr][0]=sum[nr-1][0]+best[a[nr]][0];
sum[nr][1]=sum[nr-1][1]+max(best[a[nr]][0],best[a[nr]][1]);
}
best[x][1]=sum[nr][0]+val[x];
for(int i=0;i<ad[x].size();i++)
{
p=0;
while(a[p]<ad[x][i])
p++;
p--;
best[x][1]=max(best[x][0],sum[p][0]+sum[nr][1]-sum[p][1]+val[ad[x][i]]);
best[x][1]=max(best[x][1],sum[nr][0]+val[x]+val[ad[x][i]]);
}
for(int i=0;i<inloc[x].size();i++)
{
p=0;
while(a[p]<inloc[x][i])
p++;
p--;
best[x][1]=max(best[x][1],val[inloc[x][i]]+sum[nr][1]-sum[p][1]+sum[p][0]);
}
for(int i=0;i<v[x].size();i++)
best[x][0]+=max(best[v[x][i]][0],best[v[x][i]][1]);
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i=0;i<n;i++)
val[i]=confidence[i];
for(int i=1;i<n;i++)
{
tip=protocol[i];
if(tip==0)
{
v[host[i]].push_back(i);
}
if(tip==1)
{
ad[host[i]].push_back(i);
}
if(tip==2)
{
inloc[host[i]].push_back(i);
}
}
dfs(0);
return max(best[0][0],best[0][1]);
}
Compilation message (stderr)
friend.cpp: In function 'void dfs(int)':
friend.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
friend.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
friend.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<inloc[x].size();i++)
~^~~~~~~~~~~~~~~~
friend.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
# | 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... |