Submission #1001651

#TimeUsernameProblemLanguageResultExecution timeMemory
1001651MilosMilutinovicAmusement Park (CEOI19_amusementpark)C++14
19 / 100
3052 ms460 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...