QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#162348 | #7107. Chaleur | zhouhuanyi | AC ✓ | 299ms | 16992kb | C++14 | 2.2kb | 2023-09-03 10:38:48 | 2023-09-03 10:38:49 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<cstdlib>
#include<random>
#define N 100000
using namespace std;
const int inf=(int)(1e9);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,n,m,sz,ans,ans2,deg[N+1],st[N+1],leng,tong[N+1],length;
bool used[N+1],cl[N+1];
vector<int>E[N+1];
void add(int x,int y)
{
E[x].push_back(y),E[y].push_back(x),deg[x]++,deg[y]++;
return;
}
int main()
{
int x,y,cnt,rst;
bool opt;
T=read();
while (T--)
{
n=read(),m=read(),opt=ans=ans2=sz=0;
while (((1ll*sz*(sz+1))>>1)<=m) sz++;
for (int i=1;i<=n;++i) E[i].clear(),deg[i]=cl[i]=0;
for (int i=1;i<=m;++i) x=read(),y=read(),add(x,y);
for (int i=0;i<=sz;++i)
{
length=rst=0;
for (int j=1;j<=n;++j)
if (deg[j]>=i)
tong[++length]=j,rst+=deg[j];
if (length==i)
{
cnt=0;
for (int j=1;j<=length;++j)
for (int k=0;k<E[tong[j]].size();++k)
if (deg[E[tong[j]][k]]>=i)
cnt++;
if (cnt==length*(length-1)&&rst-((length*(length-1))>>1)==m)
{
opt=1,leng=length;
for (int j=1;j<=leng;++j) st[j]=tong[j];
break;
}
}
}
if (!opt)
{
for (int i=1;i<=n;++i)
if (deg[i]<=sz-1)
{
cnt=rst=0;
for (int j=0;j<E[i].size();++j) used[E[i][j]]=1,rst+=deg[E[i][j]];
for (int j=0;j<E[i].size();++j)
for (int k=0;k<E[E[i][j]].size();++k)
cnt+=used[E[E[i][j]][k]];
if (cnt==deg[i]*(deg[i]-1)&&rst-((deg[i]*(deg[i]-1))>>1)==m)
{
leng=0;
for (int j=0;j<E[i].size();++j) used[E[i][j]]=0,st[++leng]=E[i][j];
break;
}
for (int j=0;j<E[i].size();++j) used[E[i][j]]=0;
}
}
for (int i=1;i<=leng;++i) cl[st[i]]=1;
for (int i=1;i<=n;++i)
if (!cl[i]&°[i]==leng)
ans++;
if (!ans)
{
ans=1;
for (int i=1;i<=n;++i)
if (!cl[i]&°[i]==leng-1)
ans++;
}
for (int i=1;i<=n;++i)
if (cl[i]&°[i]==leng-1)
ans2++;
if (!ans2)
{
ans2=1;
for (int i=1;i<=n;++i)
if (cl[i]&°[i]==leng)
ans2++;
}
printf("%d %d\n",ans,ans2);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6228kb
input:
3 3 2 1 2 2 3 6 6 1 2 2 3 1 3 1 4 2 5 3 6 4 1 1 2
output:
2 1 1 4 1 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 299ms
memory: 16992kb
input:
2231 1 0 5 7 4 1 3 4 3 1 3 5 4 2 3 2 4 5 5 4 2 1 2 5 2 4 2 3 5 10 3 2 2 5 1 4 4 2 4 5 1 2 1 3 3 5 3 4 1 5 5 10 1 3 2 4 1 4 5 2 2 3 1 5 5 4 1 2 3 4 5 3 5 9 2 5 3 5 2 3 2 1 4 3 3 1 4 1 4 5 2 4 5 4 4 2 4 1 4 5 4 3 5 9 4 1 4 5 3 4 2 4 2 1 3 1 2 5 3 5 3 2 5 4 2 5 2 3 2 1 2 4 5 9 5 2 1 3 4 3 1 2 5 4 4 2 5...
output:
1 1 3 1 4 1 1 5 1 5 2 1 4 1 2 1 4 1 2 1 2 1 3 1 4 1 4 1 1 5 2 1 4 1 1 5 1 5 1 5 3 1 4 1 4 1 4 1 3 1 3 1 4 1 4 1 2 1 4 1 4 1 1 5 1 5 2 1 4 1 4 1 4 1 3 1 2 1 4 1 2 1 4 1 4 1 4 1 3 1 1 5 4 1 4 1 1 5 2 1 4 1 2 1 2 1 1 5 4 1 1 5 3 1 4 1 1 5 2 1 1 5 3 1 3 1 1 5 3 1 3 1 2 1 1 5 4 1 3 1 1 5 2 1 3 1 2 1 2 1 ...
result:
ok 2231 lines
Extra Test:
score: 0
Extra Test Passed