이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[1010];
void AE(int x,int y){
adj[x].push_back(y);
adj[y].push_back(x);
}
int bruteforce(int n,int confidence[],int host[],int protocol[]){
for(int i=1;i<n;i++){
if(protocol[i])
for(auto x:adj[host[i]])
AE(x,i);
if(protocol[i]%2==0)
AE(i,host[i]);
}
int ans=0;
for(int msk=1;msk<1<<n;msk++){
int conf=0;
for(int i=0;i<n;i++) if(msk&1<<i)
conf+=confidence[i];
for(int i=0;i<n;i++) if(msk&1<<i)
for(auto y:adj[i]) if(msk&1<<y)
conf=-1; ans=max(ans,conf);
}
return ans;
}
int wieht[1010],dp1[1010],dp2[1010];
void dfs(int n){
dp1[n]=0;
dp2[n]=wieht[n];
for(auto x:adj[n]){
dfs(x);
dp2[n]+=dp1[x];
dp1[n]+=max(dp2[x],dp1[x]);
}
}
int itsatree(int par[],int conf[],int n){
for(int i=1;i<n;i++)
adj[par[i]].push_back(i);
memcpy(wieht,conf,4*n);
dfs(0);
return max(dp1[0],dp2[0]);
}
int amatching(int host[],int protoc[],int n){
for(int i=1;i<n;i++){
if(protoc[i])
for(auto x:adj[host[i]])
AE(x,i);
else AE(i,host[i]);
}
return -1;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
if(n<=10) return bruteforce(n,confidence,host,protocol);
set<int>st;
int ans=0,ans2=0;
for(int i=0;i<n;i++)
ans+=confidence[i],ans2=max(ans2,confidence[i]);
for(int i=1;i<n;i++)
st.insert(protocol[i]);
if(st.size()==1)
return protocol[1]==1?ans:protocol[1]?ans2:itsatree(host,confidence,n);
return amatching(host,protocol,n);
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int bruteforce(int, int*, int*, int*)':
friend.cpp:23:32: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
23 | for(auto y:adj[i]) if(msk&1<<y)
| ^~
friend.cpp:24:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
24 | conf=-1; ans=max(ans,conf);
| ^~~
# | 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... |