QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413004 | #6745. Delete the Tree | Savior | WA | 1ms | 3676kb | C++20 | 1.4kb | 2024-05-16 23:30:25 | 2024-05-16 23:30:25 |
Judging History
answer
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
#define int long long
using ll = long long;
const int inf = 1e17+7;
const int N=505;
const int mod =1e9+7;
typedef pair<int,int>P;
int mn=inf,rt=0,n=0;
int tot=0;
int sz[N];
vector<int>ans[N];
int vis[N],mx[N];
vector<int>e[N];
void get(int u,int fa){
sz[u]=1;mx[u]=0;
for(auto v:e[u]){
if(v==fa||vis[v]) continue;
get(v,u);
mx[u]=max(mx[u],sz[v]);
sz[u]+=sz[v];
}
mx[u]=max(mx[u],n-sz[u]-1);
if(mx[u]<mx[rt]) rt=u;
return;
}
void dfs(int u,int fa,int w){
if(vis[u]) return;
ans[w].push_back(u);
tot=max(tot,w);
vis[u]=1;
for(auto v:e[u]){
if(v==fa||vis[v]) continue;
mn=inf,n=sz[v];
mx[rt=0]=inf;
get(v,u);
dfs(rt,0,w+1);
}
}
void solve(){
cin>>n;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
mx[rt=0]=inf;
get(1,0);
dfs(rt,0,1);
cout<<tot<<endl;
for(int i=tot;i>=1;i--){
cout<<ans[i].size()<<' ';
for(auto it:ans[i])
cout<<it<<' ';
cout<<endl;
}
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t=1;//cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
5 1 2 1 3 1 4 4 5
output:
3 2 2 3 2 1 5 1 4
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3572kb
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 183 32 334 254 331 348 54 430 275 410 360 468 140 179 93 327 128 365 122 43 46 399 398 269 130 227 412 61 295 98 30 197 397 95 192 266 48 310 283 127 123 7 154 317 302 158 65 218 306 191 309 210 20 190 204 484 182 429 362 99 92 347 39 488 58 115 228 8 346 111 386 498 408 259 289 333 256 352 26...
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3528kb
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 249 1 323 205 480 454 142 346 389 232 228 357 362 316 163 176 210 294 124 339 223 409 175 474 181 81 140 301 134 215 471 4 122 456 160 484 331 318 22 69 105 342 219 363 446 194 408 25 101 84 407 60 488 348 157 358 211 423 169 403 303 499 486 286 436 356 493 190 47 366 347 90 213 264 75 398 102 70 ...
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3512kb
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:
10 60 413 74 147 335 410 451 149 269 308 333 490 58 81 416 341 270 346 329 280 46 76 452 94 184 125 153 61 185 284 114 367 283 83 16 177 465 65 353 38 304 402 222 117 498 272 380 323 399 157 198 44 224 306 244 165 143 73 288 278 233 185 301 176 241 386 264 314 261 425 156 420 441 183 318 328 494 11...
result:
ok
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3676kb
input:
500 147 209 104 147 13 209 209 466 104 485 17 104 13 214 13 179 151 466 176 466 130 485 286 485 17 359 17 178 214 486 55 214 179 350 179 327 151 167 151 498 146 176 102 176 99 130 130 232 286 294 286 389 56 359 330 359 178 488 178 441 440 486 210 486 55 157 55 458 237 350 350 352 327 371 317 327 167...
output:
11 3 382 140 422 11 303 62 223 442 189 169 199 69 74 283 280 26 219 292 9 319 271 100 171 337 376 1 27 363 381 491 434 120 109 85 184 19 500 225 25 240 334 457 85 134 320 288 207 96 465 338 298 141 203 449 220 245 331 132 43 266 311 343 128 448 121 10 164 144 326 369 77 408 388 270 48 243 481 293...
result:
wrong answer Integer 11 violates the range [0, 10]