이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib>
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
//#define int long long
//#define double long double
const int mod=1e9+7,mxn=2e5+5,lg=60,inf=1e9,minf=-1e9,mx=3e4;
int dp[mxn+10][2];
int findSample(int n, int confidence[], int host[], int protocol[]){
for(int i=0;i<n;i++)dp[i][1]=confidence[i];//take
for(int i=n-1;i>=1;i--){
if(protocol[i]==0){
dp[host[i]][0]+=dp[i][1];
dp[host[i]][1]+=dp[i][0];
}
else if(protocol[i]==1){//can take both parent and i
dp[host[i]][1]+=dp[i][1];
dp[host[i]][0]+=dp[i][0];//same friend
}
else{
dp[host[i]][1]=max(dp[host[i]][1]+dp[i][0],dp[i][1]+dp[host[i]][0]);
dp[host[i]][0]+=dp[i][0];
}
dp[host[i]][1]=max(dp[host[i]][1],dp[host[i]][0]);
//cout<<host[i]<<" "<<i<<" "<<dp[host[i]][0]<<" "<<dp[host[i]][1]<<'\n';
}
return max(dp[0][0],dp[0][1]);
}/*
int32_t main(){
fastio
int n;cin>>n;
int x[n+1],y[n+1],z[n+1];
for(int i=0;i<n;i++)cin>>x[i];
for(int i=1;i<n;i++)cin>>y[i]>>z[i];
cout<<findSample(n,x,y,z);
}*/
# | 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... |