QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#634422 | #9453. Graph Generator | ucup-team3510# | AC ✓ | 171ms | 23732kb | C++14 | 1.6kb | 2024-10-12 17:17:31 | 2024-10-14 16:53:45 |
Judging History
answer
#include <bits/stdc++.h>
#define N 100011
#define pii pair<int,int>
#define s1 first
#define s2 second
using namespace std;
int t,n,m;vector<int> G[N],nG[N];
int deg[N],fa[N],siz[N];bool vis[N];
int get(int a){return fa[a]==a?a:fa[a]=get(fa[a]);}
void merge(int a,int b)
{
a=get(a);b=get(b);
if(a==b)return;
fa[b]=a;siz[a]+=siz[b];
}
vector<pii> vv;
vector<int> ans[N];
int main()
{
scanf("%d",&t);while(t--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)G[i].clear(),nG[i].clear(),deg[i]=0;
for(int i=1;i<=m;++i)
{
int u,v;scanf("%d%d",&u,&v);
G[u].push_back(v);G[v].push_back(u);
++deg[u];++deg[v];
}
for(int i=1;i<=n;++i)
{
fa[i]=i;vis[i]=0;siz[i]=1;
}
vv.clear();
for(int i=1;i<=n;++i)vv.push_back({deg[i],i});
sort(vv.begin(),vv.end());
// printf("vv:");for(pii x:vv)printf("{%d,%d} ",x.s1,x.s2);putchar(10);
for(int i=1;i<=n;++i)
{
for(int j:G[i])if(deg[i]>deg[j]||deg[i]==deg[j]&&i>j)nG[i].push_back(j);
}
for(int i=1;i<=n;++i)ans[i].clear();
bool ok=1;
for(int i=0;i<vv.size();++i)
{
int u=vv[i].s2;
for(int v:nG[u])if(!vis[get(v)])ans[u].push_back(v),vis[get(v)]=1;
int sz=0;
for(int v:nG[u])if(vis[get(v)])sz+=siz[get(v)],vis[get(v)]=0;
if(sz!=nG[u].size())
{
ok=0;break;
}
for(int v:ans[u])merge(u,v);
}
if(!ok)
{
printf("No\n");
}
else
{
printf("Yes\n");
for(int i=0;i<vv.size();++i)
{
int u=vv[i].s2;
printf("%d %d ",u,(int)ans[u].size());
for(int v:ans[u])printf("%d ",v);putchar(10);
}
}
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12148kb
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 3 No
result:
ok 3 cases passed
Test #2:
score: 0
Accepted
time: 171ms
memory: 23732kb
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 4 9 8 10 No No No Yes 6 0 2 0 3 1 2 4 1 3 5 1 3 1 2 2 6 No No Yes 2 0 3 0 7 1 3 4 0 5 1 4 6 1 4 1 3 4 2 7 Yes 4 0 5 0 7 0 8 0 9 0 6 0 10 0 3 2 6 10 2 5 5 10 7 9 8 1 2 8 4 Yes 9 0 4 0 6 0 7 0 8 0 5 2 7 8 2 2...
result:
ok 4176 cases passed
Extra Test:
score: 0
Extra Test Passed