1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "unordered_map" #include "assert.h" #include "set" #include "queue" using namespace std; #define MAXN 19
#define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per( i , a , b ) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all( x ) (x).begin(), (x).end() #define mem( a ) memset(a, 0, sizeof a) typedef long long ll; typedef double db; const int P = 998244353; int n , m; ll C; ll A[MAXN]; pair<ll,int> a[MAXN]; int G[MAXN][MAXN]; int dp[1 << 18 | 6][19] , f[1 << 18 | 6] , ed[1 << 18 | 6] , idx[MAXN] , mnp[1 << 18 | 6]; int pd[MAXN][2];
void Inc( int& a , int b ) { a = ( a + b < P ? a + b : a + b - P ); }
int ipw[666];
void solve( ) { cin >> n >> m >> C; rep( i , 1 , n ) scanf("%lld",A + i) , a[i] = mp( A[i] , i ) , idx[i] = i; sort( idx + 1 , idx + 1 + n , []( int o , int b ) { return a[o] < a[b]; } ); ipw[0] = 1; rep( i , 1 , 60 ) ipw[i] = ipw[i - 1] * 1ll * ( P + 1 >> 1 ) % P; rep( i , 1 , m ) { int u , v; scanf("%d%d",&u,&v); G[u][v] = G[v][u] = 1; } rep( i , 1 , ( 1 << n ) - 1 ) { rep( u , 1 , n ) if( i & ( 1 << u - 1 ) ) rep( v , 1 , n ) if( i & ( 1 << v - 1 ) ) if( G[u][v] ) ed[i] = 1; mnp[i] = 0; rep( u , 1 , n ) if( i & ( 1 << u - 1 ) ) { if( !mnp[i] || a[mnp[i]] > a[u] ) mnp[i] = u; } } f[0] = 1; rep( s , 1 , ( 1 << n ) - 1 ) { int x = ( s & -s ) , t = s ^ x; f[s] = !ed[s]; if( !t ) continue; for( int e = ( t - 1 ) & t ; ; e = ( e - 1 ) & t ) { if( !ed[s ^ e ^ x] ) Inc( f[s] , P - f[e ^ x] ); if( !e ) break; } } dp[( 1 << n ) - 1][0] = 1; per( s , ( 1 << n ) - 1 , 1 ) { rep( tt , 0 , n - 1 ) if( dp[s][idx[tt]] ) { int k = idx[tt]; int t = 0; rep( p , 1 , n ) if( ( s & ( 1 << p - 1 ) ) && a[p] > a[k] ) t |= ( 1 << p - 1 ); if( !t ) continue; int d = 1 << mnp[t] - 1; for( int x = ( t ^ d ) ; ; x = ( x - 1 ) & ( t ^ d ) ) { if( ~__builtin_popcount( x ) & 1 ) Inc( dp[s ^ x][mnp[t]] , dp[s][k] * 1ll * f[x ^ d] % P ); else Inc( dp[s ^ x ^ d][mnp[t]] , dp[s][k] * 1ll * f[x ^ d] % P * ( ( A[mnp[x ^ d]] + 1 ) % P ) % P ); if( !x ) break; } } } int as = 0; rep( s , 1 , ( 1 << n ) - 1 ) rep( k , 1 , n ) if( dp[s][k] ) { int flg = 0; rep( i , 1 , n ) if( ( s & ( 1 << i - 1 ) ) && a[i] > a[k] ) { flg = 1; break; } if( !flg ) { vector<ll> pr; ll xr = 0; rep( i , 1 , n ) if( s & ( 1 << i - 1 ) ) { pr.pb( A[i] ); xr ^= A[i]; } int res = 0; per( d , 60 , 0 ) { if( ( xr >> d + 1 << d + 1 ) != ( C >> d + 1 << d + 1 ) ) break; int val = 1; mem( pd ); pd[0][0] = 1; rep( i , 1 , pr.size() ) { rep( t , 0 , 1 ) { if( ( pr[i - 1] >> d ) & 1 ) { pd[i][t ^ 1] = ( pd[i][t ^ 1] + ( ( pr[i - 1] & ( 1ll << d ) - 1 ) + 1 ) % P * pd[i - 1][t] % P ) % P; pd[i][t] = ( 1ll * pd[i][t] + ( 1ll << d ) % P * pd[i - 1][t] ) % P; } else { pd[i][t] = ( 1ll * pd[i][t] + ( ( pr[i - 1] & ( 1ll << d ) - 1 ) + 1 ) % P * pd[i - 1][t] ) % P; } } val = ( ( pr[i - 1] & ( 1ll << d ) - 1 ) + 1 ) % P * 1ll * val % P; } if( C & ( 1ll << d ) ) { res = ( res + ( ( pd[pr.size()][1] + ( ( xr & ( 1ll << d ) ) ? P - val : 0 ) ) * 1ll * ipw[d] % P ) ) % P; } else { res = ( res + ( ( pd[pr.size()][0] + ( ( ~xr & ( 1ll << d ) ) ? P - val : 0 ) ) * 1ll * ipw[d] % P ) ) % P; } } if( xr == C ) ++ res;
as = ( as + res * 1ll * dp[s][k] ) % P; } } cout << as << endl; }
signed main( ) { freopen("counting.in", "r", stdin); freopen("counting.out", "w", stdout); solve( ); }
|