Submission #715040

#TimeUsernameProblemLanguageResultExecution timeMemory
715040keystoneLogičari (COCI21_logicari)C++14
10 / 110
79 ms6964 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = 0; j < graph[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...