# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502531 | InternetPerson10 | Amusement Park (CEOI19_amusementpark) | C++17 | 3062 ms | 324 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.
#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)
# | 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... |