#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 1e6 + 100;
const ll INF = (ll)1e18 + 100;
const int MOD = 998244353;
const int maxl = 20;
int n, m;
int f[maxl][maxl];
ll dp[1<<maxl];
ll d[1<<maxl];
int g[maxl];
int sum[1<<maxl];
bool ok[1<<maxl];
void test(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
a--; b--;
f[a][b] = 1;
f[b][a] = 2;
g[a] |= (1<<b);
g[b] |= (1<<a);
}
d[0] = 1;
for(int x = 0; x < (1<<n); x++){
int to = (1<<n)-1;
for(int i = 0; i < n; i++){
if(x & (1<<i)){
to &= g[i];
}
}
to ^= to & x;
for(int y = 0, lg = 0; ; y = (y + (1<<n) - to) & to){
sum[y] = 0; ok[y] = 1;
if(y){
while((1<<(lg+1)) <= y) lg++;
if(y == (1<<lg)){
for(int i = 0; i < n; i++){
if(x & (1<<i)){
sum[y] += f[i][lg] - 1;
}
}
} else{
ok[y] = ok[y ^ (1<<lg)];
if(g[lg] & y) ok[y] = 0;
sum[y] = sum[1<<lg] + sum[y ^ (1<<lg)];
}
if(ok[y]){
int mask = y | x;
dp[mask] = (dp[mask] + sum[y] * d[x] + dp[x]) % MOD;
d[mask] = (d[mask] + d[x]) % MOD;
}
}
if(y == to) break;
}
}
cout << dp[(1<<n)-1];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t; t = 1;
while(t--) test();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |