QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508288 | #5502. Dazzling Mountain | SorahISA | AC ✓ | 1567ms | 214848kb | C++20 | 5.8kb | 2024-08-07 12:53:22 | 2024-08-07 12:53:23 |
Judging History
answer
#ifndef NYCU_MyGO
#define NYCU_MyGO
#include NYCU_MyGO __FILE__ NYCU_MyGO
void solve() {
int N; cin >> N;
vector<vector<int>> adj(N);
for (int i = 0; i < N-1; ++i) {
int u, v; cin >> u >> v, --u, --v;
adj[u].eb(v), adj[v].eb(u);
}
vector<int> sz(N, 1), sz_leaf(N, 0), sum_sz_leaf(N+1, 0);
function<void(int, int)> dfs = [&](int now, int lst) {
for (int x : adj[now]) {
if (x == lst) continue;
dfs(x, now);
sz[now] += sz[x], sz_leaf[now] += sz_leaf[x];
}
if (sz[now] == 1) sz_leaf[now] = 1;
sum_sz_leaf[sz[now]] += sz_leaf[now];
};
dfs(0, -1);
vector<int> ans;
for (int c = 1; c <= N; ++c) {
if (sum_sz_leaf[c] == sum_sz_leaf[1]) ans.eb(c);
}
cout << SZ(ans) << "\n";
for (int i = 0, k = SZ(ans); i < k; ++i) cout << ans[i] << " \n"[i == k-1];
}
int32_t main() {
fastIO();
int t = 1; cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
using f80 = long double;
#define dobule f80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "\u001b[33m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
#endif
/**
*
*
*
* iiiiii iiiiiiiiii iiiiiiiiiiiiii
* iiiiiiiiiiiii iiiiiii iiii iiiiiiiiiiiiiii ii iiii
* iiiiiiii iiiiiiiii iiii iiii iii iii iiiiiiiiii
* iiiiiii iiiiii iiii iiii ii iiiiiiiiii iiii iiii
* iiiiii iiiii iiii iiii iii iiii iiiiiiiiiiiiiiiii ii
* iiiiii iiiiiii iiiiiii iiiiiiii iii iiiiiiiiiiiiii iii iiii
* iiiiii iiiiiii iiiii ii iiii iiiiiiiiiii iiii iii iiii iiii iii
* iiiii iiiiiiii ii iiiii iiii iiiiiiiii iii iii iii iii ii iiii
* iiiiii iiiiiiii iiiii iiiii iiiiiiiiiiiiiiii iii iii ii iii iii iiii
* iiiii iiiiii iiii iiiiii iiiiiii iii iii iiii ii i ii iii iii
* iiiiii iiii iiiiiiiiiiiiiii iii iiii iiiii iii ii iii iii ii
* iiiii iiiiiiii iiiiiiiiii iiii iiiiiiiii ii iii ii
* iiiii iiiiii iiii iiiii iii ii ii i
* iiiiii iiiiiiii iiiii iiiii ii ii ii
* iiiii iiii iiii iiiiiiiiiiii ii
* iii iiii iiii iiiiiiii
* iiiii iiii
* iiii iiii
* iiii iiiii
* iii iiiii
* iii iiiii
* iii iiiiii
* iiiiiiiii
* iiiiii
*
*
*
**/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
1 9 1 2 2 3 3 4 3 5 2 6 6 7 7 8 7 9
output:
4 1 3 8 9
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 515ms
memory: 4064kb
input:
10000 906 675 189 555 889 491 97 791 419 175 694 713 842 788 513 159 354 670 815 652 546 253 87 89 278 563 429 522 900 202 657 331 865 35 605 735 532 612 471 657 386 7 886 856 164 224 777 73 534 481 631 711 698 240 465 115 181 191 825 311 155 709 501 207 849 294 546 591 682 96 405 210 696 861 13 781...
output:
63 1 3 4 34 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 6 1 2 3 4 5 11 28 1 2 3 4 5 6 15 16 17 18 19 20 21 2...
result:
ok 20000 lines
Test #3:
score: 0
Accepted
time: 914ms
memory: 61492kb
input:
10 257056 71485 24974 175037 254578 15503 255561 2268 184070 101954 23776 151400 163190 209539 157934 61908 8578 251032 109510 106012 63219 6393 135129 229530 202665 135202 195080 36226 54716 113653 27375 130515 126621 51348 62149 190321 116509 235895 205631 193944 184367 234172 88847 217084 158554 ...
output:
24809 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 20 lines
Test #4:
score: 0
Accepted
time: 1567ms
memory: 214848kb
input:
3 1000000 929036 746780 508756 963246 215473 613289 951642 391332 605398 514190 932199 548138 439718 525533 976267 837482 522952 131368 536100 143927 866830 627096 995333 784817 209340 817981 278894 972055 340159 479037 505969 156301 962674 345998 328184 514559 522443 340810 671564 2940 233204 19714...
output:
1000000 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 ...
result:
ok 6 lines
Test #5:
score: 0
Accepted
time: 1485ms
memory: 155712kb
input:
3 1000000 762755 663578 736521 890486 762558 739995 2696 497271 66774 285301 58082 960305 515605 849755 585841 791747 805356 25220 199034 206010 792516 101430 419916 601668 256275 440770 76325 556632 286424 45286 173087 212370 760515 256873 614983 749308 248450 520646 937026 203197 698482 110785 336...
output:
97 1 999905 999906 999907 999908 999909 999910 999911 999912 999913 999914 999915 999916 999917 999918 999919 999920 999921 999922 999923 999924 999925 999926 999927 999928 999929 999930 999931 999932 999933 999934 999935 999936 999937 999938 999939 999940 999941 999942 999943 999944 999945 999946 9...
result:
ok 6 lines
Test #6:
score: 0
Accepted
time: 973ms
memory: 93872kb
input:
4 524287 205019 282354 364309 67930 413687 214429 276475 421558 389289 353076 280299 275873 94349 273570 247189 157103 229015 223128 199377 75975 290133 428512 365384 135800 429146 366204 300847 17632 274432 256151 514401 293776 169558 105252 441686 467048 416285 490295 87525 312545 150473 67284 218...
output:
19 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 2 1 524288 18 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 917503 2 1 1000000
result:
ok 8 lines