QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627303#9449. New School TermzhouhuanyiWA 0ms3860kbC++232.1kb2024-10-10 15:29:562024-10-10 15:29:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 15:29:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-10-10 15:29:56]
  • 提交

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,int d)
{
	if (!d) cnt++;
	else cnt--;
	used[x]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i].num])
			dfs(E[x][i].num,d^E[x][i].data);
	return;
}
void dfs2(int x)
{
	for (int i=0;i<E[x].size();++i)
		if (!cl[E[x][i].num])
			cl[E[x][i].num]=!E[x][i].data?cl[x]:cl[x]^3,dfs2(E[x][i].num);
	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)
		if (find(A[i])!=find(B[i]))
		{
			adder(delta[find(A[i])],-1),adder(delta[find(B[i])],-1),add(A[i],B[i],1);
			for (int j=1;j<=(n<<1);++j) used[j]=0;
			cnt=0,dfs(A[i],0),cnt=abs(cnt),adder(cnt,1);
			if (!dp[res>>1]) adder(cnt,-1),cnt=E[A[i]].back().data=E[B[i]].back().data=0,dfs(A[i],0),cnt=abs(cnt),adder(cnt,1);
			unionn(find(A[i]),find(B[i])),delta[find(A[i])]=cnt;
		}
	for (int i=1;i<=(n<<1);++i)
		if (!cl[i])
			cl[i]=1,dfs2(i);
	for (int i=1;i<=(n<<1);++i) printf("%d",cl[i]==1);
	puts("");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3860kb

input:

2 4
1 3
2 4
1 4
1 2

output:

1010

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3 7
2 5
1 3
4 6
2 6
4 5
2 4
5 6

output:

110010

result:

ok Output is valid. OK

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3836kb

input:

1 0

output:

11

result:

wrong answer The number of 0s must be equal to that of 1s.