# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
715040 | keystone | Logičari (COCI21_logicari) | C++14 | 79 ms | 6964 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<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
int n;
cin>>n;
vector<vector<int>> graph(n);
int a,b;
for(int i=0;i<n;i++){
cin>>a>>b;
graph[a-1].push_back(b-1);
graph[b-1].push_back(a-1);
}
if(n<=20){
int ans=1e9;
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
int cnt=0;
for(auto x:graph[j]){
if(((1<<x)&i)>0){
cnt++;
}
}
if(cnt!=1) break;
if(j==n-1){
cnt=0;
for(int k=0;k<n;k++){
if(((1<<k)&i)>0) cnt++;
}
ans=min(ans,cnt);
}
}
}
if(ans==1e9) cout<<-1<<"\n";
else cout<<ans<<"\n";
return 0;
}
if(n%4!=0) {
cout<<-1<<"\n";
return 0;
}
int blue = n/2;
int red = n/2;
vector<bool> has_blue(n, false);
for (int i = 0; i < n; i++) {
int blue_cnt = 0;
for (int j = 0; j < graph[i].size(); j++) {
if (has_blue[graph[i][j]]) {
blue_cnt++;
}
}
if (blue_cnt == 1) {
blue--;
has_blue[i] = true;
}
else {
red--;
}
}
if (blue < 0 || red < 0) {
cout<<-1<<"\n";
}
else {
cout<<blue<<"\n";
}
return 0;
}
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... |