LINK:州区划分
把题目中四个条件进行规约 容易想到不合法当前仅当当前状态是一个无向图欧拉回路.
充要条件有两个 联通 每个点度数为偶数.
预处理出所有状态.
然后设(f_i)表示组成情况为i的值.
枚举子集转移 可以发现利用FST进行优化.
FST怎么做?详见另一篇文章史上最详细FST解释
code
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000000000000ll
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define gi(x) scanf("%lf",&x)
#define put(x) printf("%d
",x)
#define putl(x) printf("%lld
",x)
#define rep(p,n,i) for(RE int i=p;i<=n;++i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE int i=n;i>=p;--i)
#define vep(p,n,i) for(RE int i=p;i<n;++i)
#define pii pair<int,int>
#define mk make_pair
#define RE register
#define P 1000000007ll
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define EPS 1e-10
#define sq sqrt
#define S second
#define F first
#define mod 998244353
#define max(x,y) ((x)<(y)?y:x)
using namespace std;
char *fs,*ft,buf[1<<15];
inline char gc()
{
return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
RE int x=0,f=1;RE char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
return x*f;
}
const int MAXN=1<<21,maxn=22;
int n,m,p,maxx;
int f[maxn][MAXN],c[MAXN],g[maxn][MAXN],w[MAXN],in[MAXN];
int d[maxn],fa[maxn];
struct wy
{
int x,y;
}t[MAXN];
inline int getfather(int x){return x==fa[x]?x:fa[x]=getfather(fa[x]);}
inline int ksm(int b,int p)
{
int cnt=1;
while(p)
{
if(p&1)cnt=(ll)cnt*b%mod;
b=(ll)b*b%mod;p=p>>1;
}
return cnt;
}
inline void FWT(int *f,int op)
{
for(int len=2;len<=maxx+1;len=len<<1)
{
int mid=len>>1;
for(int j=0;j<=maxx;j+=len)
{
vep(0,mid,i)
{
if(op==1)f[i+j+mid]=(f[i+j+mid]+f[i+j])%mod;
else f[i+j+mid]=(f[i+j+mid]-f[i+j]+mod)%mod;
}
}
}
}
inline int pd(int x)
{
if(c[x]<=1)return 0;
int cnt=c[x];
rep(1,n,i)fa[i]=i,d[i]=0;
rep(1,m,i)
{
if(((1<<(t[i].x-1))&x)&&((1<<(t[i].y-1))&x))
{
d[t[i].x]^=1;d[t[i].y]^=1;
int xx=getfather(t[i].x);
int yy=getfather(t[i].y);
if(xx==yy)continue;
fa[xx]=yy;--cnt;
}
}
if(cnt!=1)return 1;
rep(1,n,i)if(d[i])return 1;
return 0;
}
int main()
{
//freopen("1.in","r",stdin);
get(n);get(m);get(p);
rep(1,m,i)
{
int get(x),get(y);
t[i]=(wy){x,y};
}
rep(1,n,i)get(w[i]);
maxx=1<<n;--maxx;
rep(1,maxx,i)
{
int sum=0;c[i]=c[i>>1]+(i&1);
rep(1,n,j)if(i&(1<<(j-1)))sum+=w[j];
sum=ksm(sum,p);in[i]=ksm(sum,mod-2);
//cout<<pd(i)<<' '<<i<<endl;
//cout<<sum<<endl;
if(pd(i))g[c[i]][i]=sum;
//cout<<g[c[i]][i]<<endl;
}
rep(1,n,i)FWT(g[i],1);
f[0][0]=1;FWT(f[0],1);
rep(1,n,i)
{
vep(0,i,j)
rep(0,maxx,k)f[i][k]=(f[i][k]+(ll)f[j][k]*g[i-j][k])%mod;
FWT(f[i],-1);
rep(0,maxx,k)f[i][k]=(ll)f[i][k]*in[k]%mod;
FWT(f[i],1);
}
FWT(f[n],-1);
put(f[n][maxx]);
return 0;
}