QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100827 | #5827. 异或图 | vincy | 0 | 2ms | 3324kb | C++14 | 1.7kb | 2023-04-28 11:32:14 | 2023-04-28 11:32:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PR pair<int,int>
#define fi first
#define se second
using namespace std;
const long long N=1e3+5,M=1e5+5,md=998244353,F=1e9;
long long n,m,C,a[N],u[N],v[N],f[N],siz[N],cnt,num[M],b[N],g[M],ans,h[3],H[3];
inline ll read()
{
ll x=0,f=1;
char ch=getchar();
while(!isdigit(ch)) { if(ch=='-') f=-1; ch=getchar(); }
while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
ll solve(int n)
{
ll ans=0;
for (int i=63;i>=0;i--)
{
int sum=0; h[0]=h[1]=0; h[2]=1;
for (int j=1;j<=n;j++)
{
ll A=(1ll<<i),B=b[j]&((1ll<<i)-1);
if ((b[j]>>i)&1)
{
H[0]=(h[0]*A+h[1]*B)%md;
H[1]=(h[0]*B+h[1]*A)%md;
H[2]=h[2]*B%md;
H[sum]=(H[sum]+h[2])%md;
tie(h[0],h[1],h[2])=tie(H[0],H[1],H[2]);
sum^=1;
} else
{
h[0]=h[0]*B%md; h[1]=h[1]*B%md; h[2]=h[2]*B%md;
}
} ans=(ans+h[(C>>i)&1])%md;
if (sum!=((C>>i)&1)) break;
} return ans;
}
int gf(int x) { return f[x]==x?x:f[x]=gf(f[x]); }
int merge(int x,int y) { f[x]=y; siz[y]+=siz[x]; }
int main()
{
cin>>n>>m>>C;
for (int i=1;i<=n;i++) a[i]=read(),a[i]++;
for (int i=0;i<m;i++) u[i]=read(),v[i]=read();
for (int S=0;S<(1<<m);S++)
{
for (int i=1;i<=n;i++) f[i]=i,siz[i]=1; cnt=0; num[S]=num[S>>1]+(S&1); g[S]=1;
for (int i=0;i<m;i++)
{
if (S&(1<<i))
{
int x=gf(u[i]),y=gf(v[i]);
if (x!=y) { if (a[f[x]]<a[f[y]]) merge(y,x); else merge(x,y); }
}
}
for (int i=1;i<=n;i++)
if (f[i]==i) { if (siz[i]%2) b[++cnt]=a[i]; else g[S]=g[S]*a[i]%md; }
(g[S]*=solve(cnt))%=md;
if (num[S]&1) (ans-=g[S])%=md; else (ans+=g[S])%=md;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 2ms
memory: 3324kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
178331579
result:
wrong answer 1st numbers differ - expected: '231790380', found: '178331579'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%