QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176411 | #6745. Delete the Tree | SnowNorth | WA | 1ms | 3972kb | C++14 | 1.8kb | 2023-09-11 16:47:26 | 2023-09-11 16:47:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
vector<int> G[N];
int siz[N], maxs[N];
bool del[N];
vector<int> G2[N];
int f[N], id[N];
void dvd(int u, int s, int fa) {
int ms = s + 1, root = -1;
function<void(int, int)> dfs1 = [&](int u, int rt) {
siz[u] = 1;
maxs[u] = 0;
for (auto v : G[u]) {
if (del[v] || v == rt) continue ;
dfs1(v, u);
siz[u] += siz[v];
maxs[u] = max(maxs[u], siz[v]);
}
maxs[u] = max(maxs[u], s - siz[u]);
if (maxs[u] < ms) ms = maxs[u], root = u;
};
dfs1(u, 0);
G2[fa].push_back(root);
for (auto v : G[root]) {
if (del[v]) continue ;
function<void(int, int)> dfs2 = [&](int u, int rt) {
siz[u] = 1;
for (auto v : G[u]) {
if (del[v] || v == rt) continue ;
dfs2(v, u);
siz[u] += siz[v];
}
};
dfs2(v, u);
}
del[root] = 1;
for (auto v : G[root]) {
if (!del[v]) dvd(v, siz[v], root);
}
}
void dfs(int u) {
if (G2[u].empty()) f[u] = 1;
for (auto v : G2[u]) {
dfs(v);
f[u] = max(f[u], f[v] + 1);
}
}
void solve() {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dvd(1, n, 0);
dfs(0);
for (int i = 1; i <= n; i++) id[i] = i;
sort(id + 1, id + n + 1, [](int A, int B) {
return f[A] < f[B];
});
int ans = 1;
vector<int> vec[20];
for (int i = 1; i <= n; i++) {
if (i > 1 && f[id[i]] != f[id[i - 1]]) ++ans;
vec[ans].push_back(id[i]);
}
cout << ans << '\n';
for (int i = 1; i <= ans; i++) {
cout << vec[i].size() << ' ';
for (auto v : vec[i]) cout << v << ' ';
cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
input:
5 1 2 1 3 1 4 4 5
output:
3 3 2 3 4 1 5 1 1
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3664kb
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 328 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 344 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 359 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 312 358 357 356 355 354 353 352 351 350 349 348 347 346 345 265 280 279 278 277 276 275 274 273 272 27...
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3664kb
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 329 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 345 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 360 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 313 359 358 357 356 355 354 353 352 351 350 349 348 347 346 266 281 280 279 278 277 276 275 274 273 27...
result:
ok
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3972kb
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:
15 152 411 417 236 122 123 415 235 126 128 130 232 418 231 134 138 341 226 141 400 342 392 391 336 87 330 89 438 91 92 253 252 332 100 390 426 107 242 110 111 239 238 419 117 186 174 210 357 179 206 205 360 183 370 203 173 369 202 368 361 191 200 364 194 197 384 148 220 219 152 347 154 155 217 158 3...
result:
wrong answer Integer 15 violates the range [0, 10]