이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
int co[100000];
int ho[100000];
int pro[100000];
typedef pair<int,int> P;
vector<P> son[100000];
int dp[100000][2];
int temp[100000];
int ans(int v,int type) {
if (dp[v][type]!=-1) {
return dp[v][type];
}
if (type==0) {
int ret=0;
int sum=0;
for(int i=0;i<son[v].size();i++) {
if (son[v][i].second==0)
sum+=ans(son[v][i].first,1);
else
sum+=ans(son[v][i].first,0);
}
ret=sum;
dp[v][type]=ret;
return ret;
}
int ret=0;
int sum=0;
for(int i=0;i<son[v].size();i++) {
if (son[v][i].second==0)
sum+=ans(son[v][i].first,1);
else
sum+=ans(son[v][i].first,0);
}
ret=sum;
for(int i=0;i<son[v].size();i++) {
int nt=son[v][i].first;
if (son[v][i].second==2) {
ret=max(ret,sum+ans(nt,1)-ans(nt,0));
}
if (son[v][i].second==0) {
sum-=ans(nt,1)-ans(nt,0);
}
if (son[v][i].second==1) {
sum+=ans(nt,1)-ans(nt,0);
}
ret=max(ret,sum);
}
ret=max(ret,sum+co[v]);
dp[v][type]=ret;
return ret;
}
int findSample(int nn,int conf[],int hos[],int prot[]) {
memset(dp,-1,sizeof(dp));
n=nn;
for(int i=0;i<n;i++) {
co[i]=conf[i];
ho[i]=hos[i];
pro[i]=prot[i];
}
for(int i=1;i<n;i++) {
son[ho[i]].push_back(P(i,pro[i]));
}
return ans(0,1);
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int ans(int, int)':
friend.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<son[v].size();i++) {
| ~^~~~~~~~~~~~~~
friend.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;i<son[v].size();i++) {
| ~^~~~~~~~~~~~~~
friend.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<son[v].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... |