Submission #502531

#TimeUsernameProblemLanguageResultExecution timeMemory
502531InternetPerson10Amusement Park (CEOI19_amusementpark)C++17
19 / 100
3062 ms324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool bad[20][20]; const ll MOD = 998244353; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> edges(m); for(int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; edges[i] = {x, y}; bad[y][x] = true; } ll ans = 0; vector<int> nums(n); for(int i = 0; i < n; i++) nums[i] = i; for(int i = 0; i < (1 << m); i++) { vector<vector<int>> adj(n); for(int j = 0; j < m; j++) { if(i & (1 << j)) swap(edges[j].first, edges[j].second); adj[edges[j].first].push_back(edges[j].second); } bool ok = true; queue<int> q; vector<bool> done(n); for(int j = 0; j < n; j++) { if(adj[j].size() == 0) { q.push(j); done[j] = true; } } while(q.size()) { int p = q.front(); q.pop(); for(int j = 0; j < n; j++) { for(int k = 0; k < adj[j].size(); k++) { if(adj[j][k] == p) { adj[j].erase(adj[j].begin() + k); break; } } if(adj[j].size() == 0 && !done[j]) { q.push(j); done[j] = true; } } } int g = 0; for(int j = 0; j < n; j++) { if(!done[j]) ok = false; } for(int j = 0; j < m; j++) { if(i & (1 << j)) { swap(edges[j].first, edges[j].second); g++; } } if(ok) ans += g; } cout << ans << '\n'; }

Compilation message (stderr)

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:42:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                 for(int k = 0; k < adj[j].size(); k++) {
      |                                ~~^~~~~~~~~~~~~~~
#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...