QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#644128 | #9453. Graph Generator | yhddd | AC ✓ | 91ms | 9924kb | C++20 | 2.0kb | 2024-10-16 11:08:47 | 2024-10-16 11:08:47 |
Judging History
answer
#include<bits/stdc++.h>
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=100010;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,m;
int head[maxn],tot;
struct nd{
int nxt,to;
}e[maxn<<1];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int d[maxn],id[maxn],rnk[maxn];
vector<int> ans[maxn];
int fa[maxn],siz[maxn];
bool vis[maxn];
int f[maxn];
int fd(int x){
if(f[x]==x)return x;
return f[x]=fd(f[x]);
}
void work(){
n=read();m=read();
for(int i=1;i<=n;i++)d[i]=head[i]=0,ans[i].clear();tot=0;
for(int i=1;i<=m;i++){
int u=read(),v=read();
add(u,v),add(v,u);
d[u]++,d[v]++;
}
for(int i=1;i<=n;i++)id[i]=i,siz[i]=1;
sort(id+1,id+n+1,[&](int u,int v){return d[u]>d[v];});
for(int i=1;i<=n;i++)rnk[id[i]]=i;
for(int u=1;u<=n;u++){
fa[u]=0;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(rnk[v]<rnk[u]&&(!fa[u]||rnk[v]>rnk[fa[u]]))fa[u]=v;
}
if(fa[u])ans[fa[u]].pb(u);
// cout<<u<<" "<<fa[u]<<"\n";
}
for(int i=1;i<=n;i++)f[i]=i;
for(int ii=n;ii;ii--){
int u=id[ii];
// cout<<siz[u]<<" "<<m<<"\n";
for(int v:ans[u])f[v]=u,siz[u]+=siz[v];
int num=1;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(fd(v)==u)++num;
}
if(num!=siz[u]){puts("No");return ;}
m-=siz[u]-1;
}
if(m){puts("No");return ;}
puts("Yes");
for(int i=n;i;i--){
printf("%lld %lld ",id[i],ans[id[i]].size());
for(int j:ans[id[i]])printf("%lld ",j);puts("");
}
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=read();
while(T--)work();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7892kb
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 1 0 4 0 3 1 4 2 2 1 3 No
result:
ok 3 cases passed
Test #2:
score: 0
Accepted
time: 91ms
memory: 9924kb
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 8 0 9 0 6 0 5 0 2 1 9 10 0 7 1 10 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 2 0 7 0 3 1 7 6 0 5 1 6 4 1 5 1 3 2 3 4 Yes 4 0 9 0 8 0 7 0 5 0 10 0 6 0 3 2 6 10 2 5 3 5 7 8 9 1 2 2 4 Yes 9 0 4 0 6 0 8 0 7 0 5 2 7 8 3 2 ...
result:
ok 4176 cases passed
Extra Test:
score: 0
Extra Test Passed