QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635557 | #9453. Graph Generator | ucup-team3586# | AC ✓ | 88ms | 11788kb | C++23 | 1.7kb | 2024-10-12 20:09:36 | 2024-10-14 16:54:07 |
Judging History
answer
#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
vector<int> e[1<<17],g[1<<17];
int fa[1<<17],to[1<<17],from[1<<17];
int u[1<<17],v[1<<17],d[1<<17];
signed main()
{
for(int T=read();T--;)
{
int n=read(),m=read();
for(int i=1; i<=n; ++i) e[i].clear(),g[i].clear(),d[i]=0;
for(int i=1; i<=m; ++i)
u[i]=read(),v[i]=read(),
++d[u[i]],++d[v[i]];
for(int i=1; i<=n; ++i) from[i]=i;
sort(from+1,from+n+1,[&](int x,int y){return d[x]<d[y];});
for(int i=1; i<=n; ++i) to[from[i]]=i;
for(int i=1; i<=n; ++i) fa[i]=n+1;
for(int i=1; i<=m; ++i)
{
int U=to[u[i]],V=to[v[i]];
if(U>V) swap(U,V);
// printf("edge %d %d\n",U,V);
fa[U]=min(fa[U],V),
e[U].push_back(V);
}
// for(int i=1; i<=n; ++i)
for(int i=1; i<=n; ++i)
sort(e[i].begin(),e[i].end());
bool gg=0;
for(int i=1; i<=n; ++i)
{
int w=i;
for(int j:e[i])
{
w=fa[w];
if(w==n+1){gg=1;break;}
if(w!=j){gg=1;break;}
}
if(gg) break;
if(fa[w]!=n+1){gg=1;break;}
}
if(gg){puts("No");continue;}
puts("Yes");
for(int i=1; i<=n; ++i) if(fa[i]<=n)
g[fa[i]].push_back(i);
for(int i=1; i<=n; ++i)
{
printf("%d ",from[i]);
if(g[i].empty()) puts("0");
else
{
printf("%d ",(int)g[i].size());
int z=g[i].back();
for(int j:g[i]) if(j!=z) printf("%d ",from[j]);
printf("%d\n",from[z]);
}
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
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 1 0 2 0 3 0 Yes 1 0 3 0 4 1 3 2 2 1 4 No
result:
ok 3 cases passed
Test #2:
score: 0
Accepted
time: 88ms
memory: 11788kb
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 2 0 5 0 6 0 9 1 2 3 0 4 2 5 6 7 1 3 10 1 7 1 4 8 9 4 10 No No No Yes 6 0 2 0 3 1 2 4 1 3 5 1 4 1 2 6 5 No No Yes 2 0 3 0 7 1 3 4 0 5 1 4 6 1 5 1 3 2 7 6 Yes 4 0 5 0 7 0 8 0 9 0 6 0 10 0 3 2 6 10 2 5 5 7 8 9 3 1 2 4 2 Yes 9 0 4 0 6 0 7 0 8 0 5 2 7 8 2 2 6 5 3 1 2 1 2 4 3 Yes 3 0 4 0 5 1 4 6 0...
result:
ok 4176 cases passed
Extra Test:
score: 0
Extra Test Passed