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>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
// const int maxN;
ll dp[1 << 18];
int popc[1 << 18];
bool g[20][20], good[1 << 18];
ll binpow(ll a, ll b) {
a %= mod;
if (!b) return 1;
if (b & 1) return a * binpow(a, b - 1) % mod;
return binpow(a * a, b >> 1);
}
ll inv(ll x) {
return binpow(x, mod - 2);
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y; cin >> x >> y;
x--; y--; g[x][y] = g[y][x] = 1;
} for (int i = 0; i < (1 << n); i++) good[i] = 1;
for (int msk = 0; msk < (1 << n); msk++) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (!(msk & (1 << i))) continue;
if (!(msk & (1 << j))) continue;
if (g[i][j]) good[msk] = 0;
}
}
} dp[0] = 1;
for (int msk = 0; msk < (1 << n); msk++) {
popc[msk] = popc[msk >> 1] + (msk & 1);
for (int i = msk; i; i = (i - 1) & msk) {
if (!good[i]) continue;
if (popc[i] & 1) dp[msk] += dp[msk ^ i];
else dp[msk] -= dp[msk ^ i];
dp[msk] %= mod;
}
} cout << (((dp[(1 << n) - 1] * m) % mod * inv(2)) % mod + mod) % mod;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
amusementpark.cpp: In function 'void open_file(std::string)':
amusementpark.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |