이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,t,n;
int ans=1e9;
set<pair<int,int>>s;
vector<int>tree[100007];
vector<int>leaves;
vector<bool>st;
long long buttons[100007];
int cost[100007][2][2];//vertice, iflit,ifpressed
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<n;i++){
cin>>a>>b;
tree[a].push_back(b);
tree[b].push_back(a);
buttons[a]+=1<<(b-1);
buttons[b]+=1<<(a-1);
}
for(int i=1;i<=n;i++){
if(tree[i].size()==1)
leaves.push_back(i);
buttons[i]+=1<<(i-1);
cin>>a;
st.push_back(a);
}
reverse(st.begin(),st.end());
int a=0;
for(int i=0;i<st.size();i++){
a*=2;
a+=st[i];
}
for(int i=0;i<1<<(n/2);i++){
int bits=0;
int res=0;
for(int j=0;j<n/2;j++){
if(i&(1<<j)){
bits++;
res^=buttons[j+1];
}
}
s.insert({res,bits});
//cout<<res<<" "<<bits<<"\n";
}
for(int i=0;i<1<<((n+1)/2);i++){
int bits=0;
int res=a;
for(int j=0;j<(n+1)/2;j++){
if(i&(1<<j)){
bits++;
res^=buttons[j+n/2+1];
}
}
pair<int,int>ak=*s.lower_bound({res,-1});
//cout<<ak.first<<" "<<ak.second<<" "<<res<<" "<<bits<<"\n";
if(ak.first==res)
ans=min(ans,bits+ak.second);
}
if(ans==1e9)
cout<<"impossible";
else
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xanadu.cpp: In function 'int main()':
xanadu.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<st.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... |