QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281255 | #1256. Delete Two Vertices Again | KLPP# | WA | 0ms | 3852kb | C++17 | 2.4kb | 2023-12-10 00:44:59 | 2023-12-10 00:45:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define trav(a,b) for (auto a : b)
#define lld long long
using i64 = long long;
#define all(x) begin(x),end(x)
void solve() {
int n,m;
cin>>n>>m;
vector<array<int,2>> edges(m);
vector<vector<array<int,2>>> g(n);
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
x--;
y--;
edges[i][0]=x;
edges[i][1]=y;
g[x].push_back({y,i});
g[y].push_back({x,i});
}
vector<int> isTree(m);
vector<vector<array<int,2>>> children(n);
vector<int> visited(n);
vector<int> edgesOut(n);
vector<int> edgesIn(m);
vector<int> depth(n);
vector<int> minDepth(n);
vector<int> edgesOver(n);
vector<int> isLeaf(n);
vector<int> isArticulation(n);
vector<int> justGrandfather(n);
vector<int> current(m);
vector<int> broken(n);
auto dfs=[&](auto&&dfs,int x,int p)->void
{
visited[x]=1;
minDepth[x]=depth[x];
for(auto[y,id]:g[x]){
if(y==p)continue;
if(visited[y]){
edgesOut[x]++;
edgesIn[current[x]]++;
continue;
}
isTree[id]=1;
children[x].push_back({y,1});
depth[y]=depth[x]+1;
current[x]=id;
dfs(dfs,y,x);
if(minDepth[y]==depth[x]-1){
justGrandfather[p]=1;
}
minDepth[x]=min(minDepth[x],minDepth[y]);
}
if(children[x].size()==0){
isLeaf[x]=1;
}
edgesOver[x]=0;
for(auto[y,id]:children[x]){
if(edgesOver[y]-edgesIn[id]!=0){
isArticulation[x]=1;
broken[x]++;
}
edgesOver[x]+=edgesOver[y]-edgesIn[id];
}
edgesOver[x]+=edgesOut[x];
};
dfs(dfs,0,-1);
vector<int> sol(m);
for(int i=0;i<m;i++){
auto[x,y]=edges[i];
if(!isTree[i]){
if(isArticulation[x] || isArticulation[y]){
sol[i]=1;
}
continue;
}
if(depth[x]>depth[y])swap(x,y);
if(!isLeaf[y]){
if(isArticulation[x] || isArticulation[y]){
sol[i]=1;
}
if(x!=0 && justGrandfather[x]){
sol[i]=1;
}
continue;
}
if(x==0){
if(children[x].size()>2){
sol[i]=1;
}
continue;
}
int CARALHO=broken[x];
if(edgesOut[y]!=0)CARALHO--;
if(CARALHO!=0)sol[i]=1;
}
for(int i=0;i<m;i++){
cout<<1-sol[i];
}
cout<<'\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
//~ cin >> tt;
while (tt--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
3 3 1 2 2 3 3 1
output:
010
result:
wrong answer Deleting vertices 1 and 2 makes graph connected, but participant claims otherwise.