# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131438 | Mahdi_Jfri | Friend (IOI14_friend) | C++14 | 5 ms | 508 KiB |
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;
#define ll long long
#define pb push_back
const int maxn = 1e3 + 20;
vector<int> adj[maxn] , adj2[maxn];
int dp[maxn][4] , a[maxn];
bool is[maxn];
void plant(int v)
{
vector<int> x , y;
dp[v][1] = a[v];
for(auto u : adj[v])
{
plant(u);
if(is[u])
y.pb(u);
else
x.pb(u);
if(is[u])
dp[v][1] += dp[u][1];
else
dp[v][1] += dp[u][3];
}
// az x hichi barnemidarim
int sum1 = 0;
for(auto u : y)
sum1 += dp[u][1];
dp[v][0] = max(dp[v][0] , sum1);
// w avalin ke barmidarim
for(auto w : x)
{
int sum = 0;
for(auto u : x)
sum += dp[u][u >= w];
for(auto u : y)
{
if(u < w)
sum += dp[u][1];
else
sum += dp[u][2];
}
dp[v][0] = max(dp[v][0] , sum);
}
dp[v][1] = max(dp[v][1] , dp[v][0]);
for(auto u : x)
dp[v][2] += dp[u][1] , dp[v][3] += dp[u][1];
for(auto u : y)
dp[v][2] += dp[u][2];
assert(dp[v][2] <= dp[v][0]);
}
int findSample(int n,int A[],int host[],int pt[])
{
bool has[3] = {0 , 0 , 0};
for(int i = 1; i < n; i++)
{
has[pt[i]] = 1;
adj[host[i]].pb(i);
is[i] = (pt[i] == 1);
}
for(int i = 0; i < n; i++)
a[i] = A[i];
plant(0);
return dp[0][1];
}
Compilation message (stderr)
# | 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... |