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 <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
--a[i]; --b[i];
}
vector<vector<int>> g(n);
auto Check = [&]() {
vector<int> deg(n);
for (int i = 0; i < n; i++) {
for (int j : g[i]) {
deg[j] += 1;
}
}
vector<int> que;
for (int i = 0; i < n; i++) {
if (deg[i] == 0) {
que.push_back(i);
}
}
for (int b = 0; b < (int) que.size(); b++) {
int i = que[b];
for (int j : g[i]) {
deg[j] -= 1;
if (deg[j] == 0) {
que.push_back(j);
}
}
}
return (int) que.size() == n;
};
int res = 0;
for (int mask = 0; mask < (1 << m); mask++) {
for (int i = 0; i < n; i++) {
g[i].clear();
}
for (int i = 0; i < m; i++) {
if (mask >> i & 1) {
g[b[i]].push_back(a[i]);
} else {
g[a[i]].push_back(b[i]);
}
}
if (Check()) {
res += __builtin_popcount(mask);
}
}
cout << res << '\n';
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |