이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<int> connections(n);
for(int i = 0; i < m; i++) {
int a,b;
cin >> a >> b;
a--;
b--;
connections[a]|=1<<b;
connections[b]|=1<<a;
}
bool indep[1<<n];
int bitCount[1<<n];
int pm1[1<<n];
for(int i = 0; i < 1<<n; i++) {
indep[i]=true;
bitCount[i]=__builtin_popcount(i);
for(int j = 0; j < n; j++) {
if((i&(1<<j))!=0) {
if((connections[j]&(i^(1<<j)))!=0) {
indep[i]=false;
break;
}
}
}
pm1[i]=(bitCount[i]%2==0? -1:1);
}
vector<ll> numAcyclicGraphs(1<<n);
numAcyclicGraphs[0]=1;
for(int i = 0; i < 1<<n; i++) {
for(int j = i; j!=0; j=((j-1)&i)) {
int without = i^j;
if(!indep[j]) continue;
//cout << i << " " << j << endl;
numAcyclicGraphs[i]=(numAcyclicGraphs[i]+pm1[j]*numAcyclicGraphs[without])%mod;
}
while(numAcyclicGraphs[i]<0) numAcyclicGraphs[i]+=mod;
}
cout << numAcyclicGraphs[(1<<n)-1] * m % mod * (mod+1)/2 % mod << endl;
}
# | 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... |