이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int mod = 998244353;
const int maxn = 18;
int n, m;
int dp[1 << maxn];
bool edge[maxn][maxn];
vector<pii > edges;
void solve() {
cin >> n >> m;
if(n == 1) {
cout << "0\n";
return;
}
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
edge[a][b] = edge[b][a] = true;
edges.pb(mp(a, b));
}
for(int mask = 1; mask < (1 << n); mask++) {
if(__builtin_popcount(mask) == 1) {
dp[mask] = 1;
continue;
}
int a = -1;
for(int i = 0; i < n; i++) {
if(mask & (1 << i)) {
a = i;
break;
}
}
int cnt = 0;
for(int i = 0; i < n; i++) {
if(edge[i][a] && (mask & (1 << i))) {
cnt++;
}
}
dp[mask] = ((cnt + 1) * dp[mask ^ (1 << a)]) % mod;
}
int ans = (m * dp[(1 << n) - 1]) % mod;
if(ans % 2 == 1) {
ans = (ans + mod) / 2;
} else {
ans = ans / 2;
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# | 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... |