QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209468 | #7107. Chaleur | rqoi031 | AC ✓ | 156ms | 4264kb | C++20 | 2.7kb | 2023-10-10 15:16:29 | 2023-10-10 15:16:30 |
Judging History
answer
#include<stdio.h>
#include<utility>
// #include<set>
struct edge
{
int v,next;
};
edge e[200005];
int en,last[100005];
void add_edge(const int u,const int v)
{
e[++en]={v,last[u]};
last[u]=en;
}
int deg[100005];
int bel[100005];
// std::set<std::pair<int,int>> Ed;
void solve()
{
int n,m;
scanf("%d%d",&n,&m);
__builtin_memset(last+1,0,n<<2);
__builtin_memset(deg+1,0,n<<2);
en=0;// Ed.clear();
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
// if(Ed.find({u,v})!=Ed.end())
// {
// fprintf(stderr,"%d %d\n",u,v);
// continue;
// }
// Ed.insert({u,v});
add_edge(u,v);
add_edge(v,u);
++deg[u],++deg[v];
}
deg[0]=-1;
__builtin_memset(bel+1,0,n<<2);
int p(0);
for(int i=1;i<=n;i++)
{
p=deg[p]<deg[i]?i:p;
}
int k(0);
for(;p;k++)
{
bel[p]=deg[p]=-1;
int q(0);
for(int i=last[p];i>0;i=e[i].next)
{
const int v(e[i].v);
if(bel[v]==k)
{
bel[v]=k+1;
q=deg[q]<deg[v]?v:q;
}
--deg[v];
}
p=q;
}
fprintf(stderr,"k = %d\n",k);
int ans1(1);
for(int i=1;i<=n;i++)
{
if(~bel[i])
{
int c(0);
for(int j=last[i];j>0;j=e[j].next)
{
if(bel[e[j].v]==-1)
{
++c;
}
}
if(c==k-1)
{
++ans1;
}
}
}
int ans2(0);
for(int i=1;i<=n;i++)
{
if(bel[i]==-1)
{
int c(0);
for(int j=last[i];j>0;j=e[j].next)
{
if(~bel[e[j].v])
{
c=1;
break;
}
}
if(c==0)
{
++ans2;
}
}
}
if(!ans2)
{
ans2=1;
for(int i=1;i<=n;i++)
{
if(bel[i]==-1)
{
int c(0);
for(int j=last[i];j>0;j=e[j].next)
{
if(~bel[e[j].v])
{
++c;
}
}
if(c==1)
{
++ans2;
}
}
}
}
printf("%d %d\n",ans1,ans2);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1632kb
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: 156ms
memory: 4264kb
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