# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
715040 | 2023-03-25T21:32:21 Z | keystone | Logičari (COCI21_logicari) | C++14 | 79 ms | 6964 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Incorrect | 79 ms | 6964 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 212 KB | Output is correct |
2 | Correct | 5 ms | 212 KB | Output is correct |
3 | Correct | 6 ms | 212 KB | Output is correct |
4 | Correct | 8 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 2 ms | 300 KB | Output is correct |
9 | Correct | 16 ms | 212 KB | Output is correct |
10 | Correct | 7 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 8 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 212 KB | Output is correct |
2 | Correct | 5 ms | 212 KB | Output is correct |
3 | Correct | 6 ms | 212 KB | Output is correct |
4 | Correct | 8 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 2 ms | 300 KB | Output is correct |
9 | Correct | 16 ms | 212 KB | Output is correct |
10 | Correct | 7 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 8 ms | 212 KB | Output is correct |
13 | Incorrect | 2 ms | 340 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Incorrect | 79 ms | 6964 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |