QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410148 | #6745. Delete the Tree | lzx2017 | WA | 1ms | 5928kb | C++20 | 1.3kb | 2024-05-13 16:34:36 | 2024-05-13 16:34:37 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=30001;
int i,j,n,m,k,l,x,y,in[N],h[N],cnt,bz[N],dl[20][N],gs,sum;
struct node{
int nxt,to;
}e[N*10];
void add(int u,int v)
{
e[++cnt].nxt=h[u];
e[cnt].to=v;
h[u]=cnt;
}
int main()
{
//freopen("1.in","r",stdin);
scanf("%d",&n);
for(i=1;i<n;i++)
{
scanf("%d%d",&x,&y);
in[x]++;in[y]++;
add(x,y);
add(y,x);
}
gs=0;sum=0;
while(sum<n)
{
gs++;
for(i=1;i<=n;i++)
if(in[i]<=2&&bz[i]==0)
{
int pd=0;
for(j=h[i];j;j=e[j].nxt)
if(bz[e[j].to]==1)
{
pd=1;
break;
}
if(pd==0)
{
bz[i]=1;
dl[gs][0]++;
dl[gs][dl[gs][0]]=i;
}
}
sum+=dl[gs][0];
for(i=1;i<=dl[gs][0];i++)
{
bz[dl[gs][i]]=2;
if(in[dl[gs][i]]==1)
{
for(j=h[dl[gs][i]];j;j=e[j].nxt)
in[e[j].to]--;
in[dl[gs][i]]--;
}
else
{
x=y=0;
in[dl[gs][i]]=0;
for(j=h[dl[gs][i]];j;j=e[j].nxt)
if(bz[e[j].to]==0)
{
if(x==0) x=e[j].to;
else y=e[j].to;
}
add(x,y);
add(y,x);
}
}
}
printf("%d\n",gs);
for(i=1;i<=gs;i++)
{
printf("%d ",dl[i][0]);
for(j=1;j<=dl[i][0];j++)
printf("%d ",dl[i][j]);
printf("\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5928kb
input:
5 1 2 1 3 1 4 4 5
output:
3 3 2 3 4 1 1 1 5
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
500 183 443 32 443 334 443 254 443 331 443 348 443 54 443 430 443 275 443 410 443 360 443 443 468 140 443 179 443 93 443 327 443 128 443 365 443 122 443 43 443 46 443 399 443 398 443 269 443 130 443 227 443 412 443 61 443 295 443 98 443 30 443 197 443 397 443 95 443 192 443 266 443 48 443 310 443 28...
output:
2 499 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
500 80 180 80 254 1 180 80 337 180 323 80 248 180 205 80 189 180 480 80 330 180 454 80 498 142 180 80 193 180 346 80 89 180 389 80 125 180 232 80 93 180 228 80 327 180 357 80 417 180 362 80 278 180 316 80 312 163 180 80 310 176 180 80 463 180 210 80 478 180 294 80 185 124 180 80 143 180 339 80 253 1...
output:
3 498 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
result:
ok
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5916kb
input:
500 387 488 301 488 301 413 13 413 13 265 176 265 176 398 74 398 74 241 241 415 386 415 386 448 210 448 210 285 147 285 147 264 19 264 19 314 314 335 54 335 54 261 261 484 425 484 350 425 156 350 156 164 164 420 8 420 8 309 230 309 230 441 408 441 183 408 183 410 204 410 204 318 151 318 151 328 328 ...
output:
11 222 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 44 46 47 48 49 50 51 53 54 55 56 57 58 60 61 63 64 65 66 67 68 69 70 72 73 74 75 77 78 80 81 82 84 85 87 89 90 91 92 95 96 97 98 100 101 104 105 106 107 108 110 111 113 114 117 119 120 123...
result:
wrong answer Integer 11 violates the range [0, 10]