QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627335 | #9449. New School Term | zhouhuanyi | WA | 0ms | 3788kb | C++23 | 1.9kb | 2024-10-10 15:33:36 | 2024-10-10 15:33:37 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define N 10000
#define M 100000
#define mod 998244353
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x=x+d>=mod?x+d-mod:x+d;
return;
}
void Adder2(int &x,int d)
{
x=x+d<0?x+d+mod:x+d;
return;
}
struct reads
{
int num,data;
};
int n,m,cnt,res,cl[N+1],dp[N+1],rt[N+1],A[M+1],B[M+1],delta[N+1];
bool used[N+1];
vector<reads>E[N+1];
void add(int x,int y,int z)
{
E[x].push_back((reads){y,z}),E[y].push_back((reads){x,z});
return;
}
int find(int x)
{
if (rt[x]==x) return x;
return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
rt[x]=y;
return;
}
void adder(int x,int d)
{
if (x)
{
if (d==1)
{
res+=x;
for (int i=(n<<1);i>=x;--i) Adder(dp[i],dp[i-x]);
}
else
{
res-=x;
for (int i=x;i<=(n<<1);++i) Adder2(dp[i],-dp[i-x]);
}
}
return;
}
void dfs(int x)
{
if (!cl[x]) cnt++;
else cnt--;
used[x]=1;
for (int i=0;i<E[x].size();++i)
if (!used[E[x][i].num])
cl[E[x][i].num]=cl[x]^E[x][i].data,dfs(E[x][i].num);
return;
}
void solve(int x,int y)
{
if (find(x)!=find(y))
{
adder(delta[find(x)],-1),adder(delta[find(y)],-1),add(x,y,1);
for (int i=1;i<=(n<<1);++i) used[i]=0;
cnt=0,dfs(x),cnt=abs(cnt),adder(cnt,1);
if (!dp[res>>1]) adder(cnt,-1),cnt=E[x].back().data=E[y].back().data=0,dfs(x),cnt=abs(cnt),adder(cnt,1);
unionn(find(x),find(y)),delta[find(x)]=cnt;
}
return;
}
int main()
{
n=read(),m=read(),dp[0]=1;
for (int i=1;i<=(n<<1);++i) rt[i]=i,delta[i]=1;
for (int i=1;i<=m;++i) A[i]=read(),B[i]=read();
for (int i=1;i<=(n<<1);++i) adder(1,1);
for (int i=m;i>=1;--i) solve(A[i],B[i]);
for (int i=1;i<=(n<<1);++i) solve(1,i);
for (int i=1;i<=(n<<1);++i) printf("%d",!cl[i]);
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3788kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1000
result:
wrong answer The number of 0s must be equal to that of 1s.