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 <set>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <map>
#include <deque>
#include <stdio.h>
using namespace std;
int new_max (int a, int b) {
if (a == -1) return b;
if (b == -1) return a;
return max(a, b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<pair<int,int>> edges;
int deg[N];
for (int i = 0; i < N; i++) {
deg[i] = 0;
}
for (int i = 0; i < N; i++) {
int u, v; cin >> u >> v; --u; --v;
edges.emplace_back(u, v);
deg[u]++, deg[v]++;
}
bool s1 = true;
for (int i = 0; i < N; i++) {
s1 &= (deg[i] == 2);
}
if (s1) {
if (N % 4 == 0) {
cout << N/2;
} else {
cout << -1;
}
exit(0);
}
int lst = -1;
for (int i = 0; i < (1 << N); i++) {
vector<int> cnt;
cnt.assign(N, 0);
for (auto& p: edges) {
if (i & (1 << p.first)) cnt[p.second]++;
if (i & (1 << p.second)) cnt[p.first]++;
}
bool fine = true;
for (int i = 0; i < cnt.size(); i++) {
fine &= (cnt[i] == 1);
}
if (fine) {
lst = new_max(lst, __builtin_popcount(i));
}
}
cout << lst;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < cnt.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... |