이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
const int N = 1e5 + 5;
// 1: last position of x, -1: second-last position of x -> sum(l, r) = 0-> non-unique subarray, > 0: unique
vector <int> adj[N];
int n;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
int x, y; cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
bool sub1 = true;
for (int i = 1; i <= n; ++i) {
if ((int) adj[i].size() != 2) sub1 = false;
}
if (sub1) {
cout << (n % 4 == 0? (n / 2) : -1) << "\n";
return 0;
}
bool sub2 = (n <= 20);
if (sub2) {
int res = 1e9;
for (int msk = 0; msk < (1 << n); ++msk) {
vector <bool> b(n + 1, 0);
int cur = 0;
for (int i = 1; i <= n; ++i) {
if (msk & (1 << (i - 1))) {
b[i] = 1;
++cur;
}
}
bool ans = true;
for (int i = 1; i <= n; ++i) {
int cnt = 0;
for (int j : adj[i])
if (b[j])
++cnt;
if (cnt != 1) ans = false;
}
if (ans) {
res = min(res, cur);
}
}
cout << (res != 1e9? res : -1) << "\n";
return 0;
}
return 0;
}
# | 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... |