QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#454367 | #1256. Delete Two Vertices Again | Kevin5307 | WA | 2ms | 11836kb | C++23 | 2.2kb | 2024-06-24 20:24:09 | 2024-06-24 20:24:09 |
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)
{
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11836kb
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: 11820kb
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: 0ms
memory: 11780kb
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: -100
Wrong Answer
time: 2ms
memory: 11732kb
input:
6 7 1 2 1 3 1 6 2 4 3 4 3 5 4 6
output:
1110011
result:
wrong answer Deleting vertices 1 and 3 makes graph disconnected, but participant claims otherwise.