# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666472 | finn__ | Amusement Park (CEOI19_amusementpark) | C++17 | 3065 ms | 2260 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;
#define MOD 998244353
int main()
{
int64_t n, m;
cin >> n >> m;
vector<vector<bool>> g(n, vector<bool>(n, 0));
for (size_t i = 0; i < m; i++)
{
unsigned u, v;
cin >> u >> v;
g[u - 1][v - 1] = 1;
}
vector<int64_t> dp(1 << n, 0);
dp[0] = 1;
for (unsigned i = 1; i < 1 << n; i++)
{
unsigned const p = __builtin_popcount(i);
vector<unsigned> s;
for (unsigned k = 0; k < n; k++)
if (i & (1 << k))
s.push_back(k);
for (unsigned j = 0; j < 1 << p; j++)
{
bool is_independent = 1;
for (unsigned k = 0; k < p && is_independent; k++)
if (j & (1 << k))
for (unsigned h = 0; h < p && is_independent; h++)
if (j & (1 << h))
if (g[s[k]][s[h]] || g[s[h]][s[k]])
is_independent = 0;
if (is_independent)
{
unsigned t = 0;
for (unsigned k = 0; k < p; k++)
if (j & (1 << k))
t ^= (1 << s[k]);
dp[i] = (dp[i] +
((__builtin_popcount(t) & 1) ? 1 : -1) * dp[i ^ t] + MOD) %
MOD;
}
}
}
cout << (((dp[(1 << n) - 1] * m) % MOD) * 499122177) % MOD << '\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... |