QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454375#1256. Delete Two Vertices AgainKevin5307TL 3ms13900kbC++232.4kb2024-06-24 20:34:502024-06-24 20:34:51

Judging History

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

  • [2024-06-24 20:34:51]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:13900kb
  • [2024-06-24 20:34:50]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,m;
int u[300300],v[300300];
vector<int> G[300300];
int fa[300300],siz[300300];
int ind[300300];
int ans[300300];
int deg[300300],cur[300300];
int cnt;
vector<pii> op;
int anc(int x)
{
	while(fa[x]!=x) x=fa[x];
	return x;
}
void join(int u,int v,int d)
{
	u=anc(u);
	v=anc(v);
	if(u==v) return ;
	if(siz[u]>siz[v]) swap(siz[u],siz[v]);
	siz[v]+=siz[u];
	fa[u]=v;
	cnt--;
	op.pb(u,d);
}
void check(int u,int d)
{
	cur[u]++;
	if(cur[u]==deg[u])
		for(auto v:G[u])
			if(cur[v]==deg[v])
				join(u,v,d);
}
void del(int d)
{
	while(sz(op)&&op.back().second==d)
	{
		int x=op.back().first;
		op.pop_back();
		siz[fa[x]]-=siz[x];
		fa[x]=x;
		cnt++;
	}
}
void solve(int l,int r,int d)
{
	if(l==r)
	{
		if(cnt==1) ans[ind[l]]=1;
		return ;
	}
	int mid=(l+r)/2;
	for(int i=l;i<=mid;i++)
	{
		check(u[i],d);
		check(v[i],d);
	}
	solve(mid+1,r,d+1);
	for(int i=l;i<=mid;i++)
	{
		cur[u[i]]--;
		cur[v[i]]--;
	}
	del(d);
	for(int i=mid+1;i<=r;i++)
	{
		check(u[i],d);
		check(v[i],d);
	}
	solve(l,mid,d+1);
	for(int i=mid+1;i<=r;i++)
	{
		cur[u[i]]--;
		cur[v[i]]--;
	}
	del(d);
}
vector<array<int,3>> vect[300300];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
		siz[i]=1;
	}
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i];
	for(int i=1;i<=m;i++)
	{
		deg[u[i]]++;
		deg[v[i]]++;
		G[u[i]].pb(v[i]);
		G[v[i]].pb(u[i]);
		if(deg[u[i]])
			vect[u[i]].push_back({u[i],v[i],i});
		else
			vect[v[i]].push_back({u[i],v[i],i});
	}
	int tot=0;
	for(int i=1;i<=n;i++)
		for(auto arr:vect[i])
		{
			ind[++tot]=arr[2];
			u[tot]=arr[0];
			v[tot]=arr[1];
		}
	cnt=n-2;
	solve(1,m,0);
	for(int i=1;i<=m;i++)
		cout<<ans[i];
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13900kb

input:

4 4
1 2
2 3
3 1
4 1

output:

0101

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #2:

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

input:

3 3
1 2
2 3
3 1

output:

111

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #3:

score: 0
Accepted
time: 3ms
memory: 13800kb

input:

3 2
1 2
2 3

output:

11

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #4:

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

input:

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

output:

1011011

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #5:

score: 0
Accepted
time: 3ms
memory: 13804kb

input:

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

output:

111111111111111111111111111111111111111

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #6:

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

input:

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

output:

110111010011

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #7:

score: -100
Time Limit Exceeded

input:

300000 300000
1 125583
1 226455
2 42202
2 265465
2 292498
3 199795
4 241628
5 96520
6 100749
6 213843
7 186924
8 239025
8 286308
9 103103
10 161146
11 81159
11 151301
12 6769
12 175614
12 262561
13 165510
14 107584
14 155920
14 166283
14 186225
15 24511
15 105534
15 263647
16 16253
16 141758
16 2560...

output:


result: