QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#631773 | #9453. Graph Generator | ucup-team2279# | AC ✓ | 472ms | 13868kb | C++20 | 1.1kb | 2024-10-12 10:12:47 | 2024-10-14 16:52:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,m;
cin>>n>>m;
vector<vector<int>> e(n+1),g(n+1);
vector<int> d(n+1),b(n+1),fa(n+1),sz(n+1,1),id;
for(int u,v;m--;) cin>>u>>v,e[u].push_back(v),e[v].push_back(u),d[u]++,d[v]++;
set<array<int,2>> s;
for(int i=1;i<=n;i++) s.insert({-d[i],i});
while(s.size()){
int x=(*begin(s))[1];
s.erase(begin(s));
b[x]=1;id.push_back(x);
for(int y:e[x]) if(!b[y]){
s.erase({-d[y],y});
d[y]--;g[x].push_back(y);
s.insert({-d[y],y});
}
}
reverse(begin(id),end(id));
iota(begin(fa),end(fa),0);
auto getf=[&](int x){
while(x!=fa[x]) x=fa[x]=fa[fa[x]];
return x;
};
vector<set<int>> c(n+1);
for(int x:id){
for(int y:g[x]) c[x].insert(getf(y));
for(int y:c[x]) fa[y]=x,sz[x]+=sz[y];
if((int)g[x].size()!=sz[x]-1){
cout<<"No\n";
return;
}
}
cout<<"Yes\n";
for(int x:id){
cout<<x<<" "<<c[x].size();
for(int y:c[x]) cout<<" "<<y;
cout<<"\n";
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t;
cin>>t;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
input:
3 3 0 4 4 1 2 2 3 3 4 2 4 5 5 1 2 2 3 3 4 4 5 2 4
output:
Yes 3 0 2 0 1 0 Yes 4 0 1 0 3 1 4 2 2 1 3 No
result:
ok 3 cases passed
Test #2:
score: 0
Accepted
time: 472ms
memory: 13868kb
input:
4176 10 15 1 4 9 1 3 7 8 1 2 1 5 4 5 1 10 1 7 1 10 7 10 3 6 4 3 1 6 1 9 2 7 10 6 7 1 7 1 4 7 2 4 2 5 2 3 1 1 6 2 6 5 1 6 8 5 2 3 1 4 6 2 1 5 1 1 4 6 2 6 1 9 15 5 1 4 2 7 1 1 8 2 3 5 8 1 9 4 3 6 5 9 2 3 1 4 1 7 2 9 7 1 6 6 11 1 2 3 5 3 1 3 2 4 3 1 6 4 2 1 4 5 4 5 1 5 2 6 6 1 6 6 3 1 3 1 5 4 2 2 1 10 ...
output:
Yes 10 0 9 0 8 0 6 0 5 0 7 1 10 2 1 9 4 2 5 6 3 1 7 1 4 2 3 4 8 No No No Yes 6 0 5 0 4 1 5 3 1 4 2 1 3 1 2 2 6 No No Yes 7 0 6 0 2 0 5 1 6 3 1 7 4 1 5 1 3 2 3 4 Yes 10 0 9 0 8 0 7 0 6 0 5 0 4 0 3 2 6 10 2 5 3 5 7 8 9 1 2 2 4 Yes 9 0 8 0 7 0 6 0 4 0 5 2 7 8 3 2 5 6 2 1 3 1 2 2 4 Yes 7 0 6 0 5 0 3 0 4...
result:
ok 4176 cases passed
Extra Test:
score: 0
Extra Test Passed