# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
899107 | duckindog | Logičari (COCI21_logicari) | C++14 | 71 ms | 6156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
vector<int> ad[N];
int d[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; ++i) {
int u, v; cin >> u >> v;
ad[u].push_back(v);
ad[v].push_back(u);
}
int answer = 1e9;
for (int mask = 1; mask < (1 << n); ++mask) {
for (int i = 1; i <= n; ++i) d[i] = (mask >> i - 1 & 1);
bool good = 1;
for (int i = 1; i <= n; ++i) {
int cnt = 0;
for (int v : ad[i]) cnt += d[v];
if (cnt != 1) good = 0;
}
int cnt = 0;
for (int i = 1; i <= n; ++i) cnt += d[i];
if (good) answer = min(answer, cnt);
}
cout << (answer == 1e9 ? -1 : answer) << '\n';
}
Compilation message (stderr)
# | 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... |