QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#615192#9449. New School Termucup-team5075#RE 2ms9780kbC++233.0kb2024-10-05 17:48:552024-10-05 17:48:55

Judging History

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

  • [2024-10-05 17:48:55]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:9780kb
  • [2024-10-05 17:48:55]
  • 提交

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef unsigned long long ull;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=5005,M=1000005,U=20005;

	int n,m;
	int a[M],b[M];

	int fa[U],sz[U];
	pii stk[U];int top;
	int getf(int x){while(x!=fa[x])x=fa[x];return x;}
	si void merge(int x,int y){
		if((x=getf(x))==(y=getf(y)))return ;
		if(sz[x]<sz[y])swap(x,y);
		sz[x]+=sz[y],fa[y]=x,stk[++top]=pii(x,y);
	}
	si void back(int ver){
		while(top>ver){
			int x=stk[top].fi,y=stk[top].se;
			top--,fa[y]=y,sz[x]-=sz[y];
		}
	}

	int p[U],id1[U],id2[U],num,sum;
	bool vis[U];

	int t[U];
	si void reid(bool flag=0){
		sum=num=0;
		vector<int> all;
		for(int i=1,x,y;i<=2*n;i++){
			x=getf(i);
			if(!vis[x]){
				y=getf(i+2*n);
				all.push_back(x),all.push_back(y),vis[x]=vis[y]=1;
				if(sz[x]<sz[y])swap(x,y);
				p[++num]=sz[x]-sz[y],sum+=sz[y];
				id1[num]=x,id2[num]=y;
			}
		}
		for(int i:all)vis[i]=0;

		if(flag){
			for(int i=1;i<=num;i++)t[p[i]]++;
			num=0;
			for(int i=1;i<=2*n;i++){
				if(t[i]){
					int c=1;
					for(;t[i]>c;c<<=1)t[i]-=c,p[++num]=c*i;
					p[++num]=c*i,t[i]=0;
				}
			}
		}
	}

	template<int NN=1>
	si bool check(){
		if(NN<=n-sum)return check<min(NN*2,N)>();
		reid(1);
		bitset<NN> f;
		f[0]=1;
		for(int i=1;i<=num;i++)f|=(f<<p[i]);
		return f[n-sum];
	}

	int f[N][N];
	bool ans[U<<1];
	si void outp(){
		reid();

		f[0][0]=1;
		for(int i=1;i<=num;i++){
			for(int j=0;j<=n-sum;j++){
				if(f[i-1][j])f[i][j]=-1;
				else if(j>=p[i]&&f[i-1][j-p[i]])f[i][j]=1;
			}
		}

		assert(f[num][n-sum]);

		for(int i=num,cur=n-sum;i;i--){
			int x=id1[i],y=id2[i];
			if(f[i][cur]==-1)ans[x]=0,ans[y]=1;
			else ans[x]=1,ans[y]=0,cur-=p[i];
		}

		for(int i=1;i<=2*n;i++)cout<<ans[getf(i)];
		cout<<endl;
	}

	void mian(){
		cin>>n>>m;
		for(int i=1;i<=m;i++)cin>>a[i]>>b[i];
		for(int i=1;i<=2*n;i++)fa[i]=i,sz[i]=1,fa[i+2*n]=i+2*n;

		for(int i=m;i;i--){
			int x=a[i],y=b[i];
			if(getf(x)==getf(y)||getf(x)==getf(y+2*n))continue;
			int tmp=top;
			merge(x,y+2*n),merge(x+2*n,y);
			if(!check()){
				back(tmp);
				merge(x,y),merge(x+2*n,y+2*n);
			}
			// cerr<<"MER "<<x<<' '<<y<<endl;
			// for(int j=1;j<=2*n;j++)cerr<<getf(j)<<' '<<getf(j+2*n)<<endl;
			// cerr<<endl;
		}

		outp();
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("in.in","r",stdin));
	// assert(freopen("out.out","w",stdout));
	// assert(freopen("out.err","w",stderr));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);   
	LinkWish::mian();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9636kb

input:

2 4
1 3
2 4
1 4
1 2

output:

0101

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 1ms
memory: 7732kb

input:

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

output:

001101

result:

ok Output is valid. OK

Test #3:

score: 0
Accepted
time: 1ms
memory: 5688kb

input:

1 0

output:

10

result:

ok Output is valid. OK

Test #4:

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

input:

1 1
1 2

output:

01

result:

ok Output is valid. OK

Test #5:

score: 0
Accepted
time: 1ms
memory: 7720kb

input:

2 3
2 4
3 4
1 2

output:

0110

result:

ok Output is valid. OK

Test #6:

score: 0
Accepted
time: 1ms
memory: 7640kb

input:

3 8
4 6
3 5
1 4
2 4
1 6
1 2
3 4
4 5

output:

010101

result:

ok Output is valid. OK

Test #7:

score: 0
Accepted
time: 1ms
memory: 7592kb

input:

4 9
4 7
3 8
1 5
2 7
2 8
6 8
7 8
1 4
1 6

output:

01010110

result:

ok Output is valid. OK

Test #8:

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

input:

5 16
3 6
9 10
2 7
1 10
1 5
2 10
3 5
5 6
3 4
2 5
4 5
3 8
4 7
6 8
1 6
7 10

output:

0010111010

result:

ok Output is valid. OK

Test #9:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

6 13
4 5
2 9
3 8
4 8
4 11
10 12
3 4
3 9
5 11
2 8
5 10
5 8
1 11

output:

110110001001

result:

ok Output is valid. OK

Test #10:

score: 0
Accepted
time: 1ms
memory: 7928kb

input:

12 153
1 24
16 18
7 14
1 16
20 21
9 14
21 22
4 5
17 24
4 12
5 17
13 24
14 15
12 23
12 16
8 11
14 24
9 16
2 5
6 19
11 17
4 22
4 7
6 16
7 20
8 15
5 24
2 10
10 21
21 24
1 12
11 19
18 21
18 24
12 17
13 22
7 9
13 23
4 9
11 13
15 21
5 7
2 4
15 16
17 19
11 16
11 20
7 8
4 15
13 14
6 18
2 19
9 13
23 24
4 21
...

output:

000011100110010001111110

result:

ok Output is valid. OK

Test #11:

score: -100
Runtime Error

input:

259 33757
472 500
65 336
138 469
307 442
427 458
43 239
17 508
460 466
108 393
79 92
250 483
44 277
17 132
35 57
155 499
184 474
246 272
274 418
457 458
338 372
196 514
31 208
117 187
90 229
153 284
189 355
16 337
146 456
269 271
279 412
305 336
303 441
399 472
85 286
91 97
157 437
137 379
71 360
27...

output:


result: