# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
867379 |
2023-10-28T09:55:05 Z |
3as8 |
Logičari (COCI21_logicari) |
C++14 |
|
30 ms |
7716 KB |
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fastIO cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
#define mid ((l + r) / 2)
#define lChild ((index * 2) + 1)
#define rChild ((index * 2) + 2)
using namespace std;
ll dfs(vector<vector<ll> >& graph, vector<bool>& visited, vector<ll>& blues, vector<bool>& isBlue, ll numBlues, ll numVis, ll startIndex) {
if(numVis == graph.size()) {
for(auto el : isBlue) cout<<el<<" ";
cout<<" => "<<numBlues<<endl;
for(auto el : visited) cout<<el<<" ";
cout<<endl;
for(auto el : blues) cout<<el<<" ";
cout<<endl;
cout<<"====="<<endl;
for(auto el : blues) if(el != 1) return LLONG_MAX;
return numBlues;
}
visited[startIndex] = true;
bool canBlue = true;
for(auto el : graph[startIndex]) {
cout<<blues[el]<<" ";
canBlue &= blues[el] == 0;
}
cout<<" => "<<canBlue<<endl;
ll ans = LLONG_MAX;
for(auto el : graph[startIndex]) {
if(visited[el]) continue;
ans = min(ans, dfs(graph, visited, blues, isBlue, numBlues, numVis + 1, el));
}
if(!canBlue) {
visited[startIndex] = false;
return ans;
}
for(auto el : graph[startIndex]) blues[el]++;
for(auto el : graph[startIndex]) {
if(visited[el]) continue;
ans = min(ans, dfs(graph, visited, blues, isBlue, numBlues + 1, numVis + 1, el));
}
for(auto el : graph[startIndex]) blues[el]--;
visited[startIndex] = false;
return ans;
}
bool check(ll bls, vector<vector<ll> >& graph) {
for(int i = 0; i < graph.size(); i++) {
ll blues = 0;
for(auto el : graph[i]) {
// cout<<bls<<" "<<(1 << el)<<endl;
blues += (bls & (1 << el)) > 0;
}
if(blues != 1) return false;
}
return true;
}
void solve(ll _) {
ll n; cin>>n;
vector<vector<ll> > graph(n);
vector<ll> blues(n, 0);
vector<bool> isBlue(n, false);
vector<bool> visited(n, false);
vector<ll> degree(n, 0);
for(int i = 0; i < n; i++) {
ll x, y; cin>>x>>y;
x--; y--;
degree[x]++; degree[y]++;
graph[x].push_back(y);
graph[y].push_back(x);
}
bool sub1 = true;
for(auto el : degree) sub1 &= (el == 2);
if(sub1) {
if (n % 4 != 0) cout << -1 << endl;
else cout << n / 2 << endl;
return;
}
ll num = 0;
ll ans = LLONG_MAX;
for(int i = 0; i < (1<<n); i++) {
if(check(i, graph)) ans = min(ans, (ll)__builtin_popcountll(i));
}
cout<<(ans == LLONG_MAX ? -1 : ans)<<endl;
//cout<<dfs(graph, visited,blues, isBlue,0, 1 , 0)<<endl;
}
int main() {
fastIO
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
ll t = 0; solve(t);
}
Compilation message
Main.cpp: In function 'long long int dfs(std::vector<std::vector<long long int> >&, std::vector<bool>&, std::vector<long long int>&, std::vector<bool>&, long long int, long long int, long long int)':
Main.cpp:17:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(numVis == graph.size()) {
| ~~~~~~~^~~~~~~~~~~~~~~
Main.cpp: In function 'bool check(long long int, std::vector<std::vector<long long int> >&)':
Main.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 0; i < graph.size(); i++) {
| ~~^~~~~~~~~~~~~~
Main.cpp: In function 'void solve(long long int)':
Main.cpp:112:8: warning: unused variable 'num' [-Wunused-variable]
112 | ll num = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
23 ms |
7488 KB |
Output is correct |
6 |
Correct |
23 ms |
7516 KB |
Output is correct |
7 |
Correct |
23 ms |
7408 KB |
Output is correct |
8 |
Correct |
30 ms |
7716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
412 KB |
Output is correct |
4 |
Correct |
7 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Correct |
8 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
412 KB |
Output is correct |
4 |
Correct |
7 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Correct |
8 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
448 KB |
Output is correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
23 ms |
7488 KB |
Output is correct |
6 |
Correct |
23 ms |
7516 KB |
Output is correct |
7 |
Correct |
23 ms |
7408 KB |
Output is correct |
8 |
Correct |
30 ms |
7716 KB |
Output is correct |
9 |
Correct |
8 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
412 KB |
Output is correct |
12 |
Correct |
7 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
13 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
8 ms |
448 KB |
Output is correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |