QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454370 | #1256. Delete Two Vertices Again | Kevin5307 | TL | 2ms | 11856kb | C++23 | 2.2kb | 2024-06-24 20:26:20 | 2024-06-24 20:26:20 |
Judging History
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);
}
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++)
{
ind[i]=i;
deg[u[i]]++;
deg[v[i]]++;
G[u[i]].pb(v[i]);
G[v[i]].pb(u[i]);
}
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: 0ms
memory: 11856kb
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: 2ms
memory: 11724kb
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: 2ms
memory: 11784kb
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: 11720kb
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: 0ms
memory: 11784kb
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: 11760kb
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...