QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104747 | #6396. Puzzle: Kusabi | zbceyond | WA | 80ms | 17628kb | C++20 | 2.6kb | 2023-05-11 20:43:57 | 2023-05-11 20:43:59 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define per(i, x, y) for(int i=x;i>=y;i--)
using namespace std;
#define int long long
const int N = 2e5 + 10;
const int mod = 998244353;
int n, flag[N], dep[N], g[N];
vector<array<int, 2>> e[N];
vector<array<int, 2>> ans;
bool ok = 1;
void dfs(int u, int fa) {
array<vector<int>, 4> tmp;
for (auto [v, mark]: e[u]) {
if (v == fa)continue;
flag[v] = mark;
dep[v] = dep[u] + 1;
dfs(v, u);
if (g[v])tmp[flag[g[v]]].push_back(g[v]);
}
if (flag[u])tmp[flag[u]].push_back(u);
sort(tmp[1].begin(), tmp[1].end(), [&](int x, int y) {
return dep[x] < dep[y];
});
sort(tmp[2].begin(), tmp[2].end(), [&](int x, int y) {
return dep[x] < dep[y];
});
sort(tmp[3].begin(), tmp[3].end(), [&](int x, int y) {
return dep[x] < dep[y];
});
vector<int> rem;
for (int i = 0; i < tmp[3].size(); i++) {
if (i + 1 == tmp[3].size()) {
rem.push_back(tmp[3][i]);
break;
}
int u = tmp[3][i], v = tmp[3][i + 1];
if (dep[u] == dep[v]) {
ans.push_back({u, v});
i++;
} else rem.push_back(u);
}
set<array<int, 2>> s;
for (auto x: tmp[2])s.insert({dep[x], x});
for (auto u: tmp[1]) {
if (s.size() == 0) {
rem.push_back(u);
break;
}
auto it = s.lower_bound({dep[u], 0});
if (it != s.begin()) {
auto [_, v] = *prev(it);
ans.push_back({u, v});
s.erase({dep[v], v});
} else rem.push_back(u);
}
for (auto [x, y]: s)rem.push_back(y);
if (rem.size() > 1)ok = 0;
if (rem.size() == 1)g[u] = rem[0];
}
void solve() {
cin >> n;
int cnt = 0, x = 0, y = 0;
rep(i, 1, n - 1) {
int u, v;
string s;
cin >> u >> v >> s;
int mark = 0;
if (s == "Chang")mark = 1, y++;
if (s == "Duan")mark = 2, y--;
if (s == "Tong")mark = 3, x++;
e[u].push_back({v, mark});
e[v].push_back({u, mark});
cnt += (mark != 0);
}
if (cnt % 2 == 1 or x % 2 == 1 or y != 0)cout << "NO\n";
else {
dfs(1, 0);
if (not g[1] or not ok) {
cout << "YES\n";
for (auto [u, v]: ans)cout << u << " " << v << "\n";
} else cout << "NO\n";
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; i++) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8116kb
input:
8 2 1 - 3 1 - 4 2 Tong 5 2 Tong 6 3 Duan 7 3 - 8 7 Chang
output:
YES 4 5 8 6
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 2ms
memory: 8196kb
input:
10 2 1 Duan 3 2 Duan 4 2 - 5 4 Chang 6 2 Chang 7 1 Duan 8 6 Tong 9 6 Tong 10 3 Chang
output:
YES 10 3 8 9 6 2 5 7
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 4ms
memory: 8180kb
input:
2 2 1 Tong
output:
NO
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 75ms
memory: 16356kb
input:
100000 2 1 Duan 3 1 Duan 4 3 - 5 4 Duan 6 3 - 7 4 Duan 8 4 - 9 8 - 10 7 Duan 11 9 - 12 7 Duan 13 7 Duan 14 8 Duan 15 13 - 16 10 Duan 17 11 Duan 18 12 - 19 1 Duan 20 5 Duan 21 4 Duan 22 14 Duan 23 16 - 24 22 Duan 25 16 Duan 26 13 - 27 13 - 28 17 - 29 5 Duan 30 22 - 31 23 - 32 9 Duan 33 5 - 34 30 Duan...
output:
YES 46666 56115 88119 38802 93143 10006 31531 76473 42604 15988 6569 30148 11412 2008 64525 46703 71289 70618 81204 47748 42353 20514 97634 46131 83516 82155 66867 62410 15712 9975 4978 3205 83026 5622 48783 10902 82167 30893 93809 65878 33377 66951 94549 66936 79128 64411 8453 22475 54702 36857 629...
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 49ms
memory: 15664kb
input:
100000 2 1 - 3 2 - 4 3 - 5 4 - 6 4 - 7 6 - 8 7 - 9 5 - 10 9 - 11 10 - 12 6 - 13 12 - 14 11 - 15 9 - 16 14 - 17 16 - 18 10 - 19 15 - 20 13 - 21 20 - 22 17 - 23 22 - 24 22 Duan 25 11 - 26 12 - 27 20 - 28 18 - 29 28 - 30 16 - 31 28 - 32 30 - 33 31 - 34 28 - 35 34 - 36 35 - 37 22 - 38 34 - 39 38 - 40 35...
output:
YES 28541 5203 5981 8106 7900 7551 53424 47998 91669 86909 40295 72002 65376 32334 95652 57528 66693 91216 88445 98194 54118 44959 76761 74202 71470 64661 85084 30271 60344 41192 41421 10342 79425 12876 35989 25933 41959 39297 94979 46303 46189 10581 51797 14956 82599 41806 26090 60566 94132 48923 7...
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 80ms
memory: 16276kb
input:
100000 2 1 - 3 2 - 4 3 Duan 5 4 Chang 6 5 Duan 7 6 Chang 8 7 Duan 9 8 Chang 10 9 Duan 11 10 Chang 12 11 Duan 13 12 Chang 14 12 Duan 15 14 Chang 16 15 Tong 17 15 Tong 18 17 Duan 19 18 Duan 20 19 Chang 21 18 Duan 22 21 Duan 23 18 Chang 24 21 - 25 24 Duan 26 25 Chang 27 26 Duan 28 27 Chang 29 26 Duan 3...
output:
YES 20 19 65 55 53 52 48 46 36 35 34 22 61 58 57 56 1206 1097 1593 1522 1938 1890 1365 1217 1295 1191 2188 2158 2845 1764 1646 1408 5721 3147 2810 2746 3194 2937 2399 2710 3778 3657 3580 2668 2179 2259 2174 2122 2379 2204 2449 2392 2499 2218 2369 2233 2077 2020 9174 8244 15184 14498 15193 14362 1069...
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 55ms
memory: 15852kb
input:
100000 2 1 - 3 2 - 4 3 - 5 4 - 6 5 - 7 6 - 8 7 - 9 8 - 10 9 Duan 11 10 - 12 11 Chang 13 12 Duan 14 13 Chang 15 14 - 16 15 - 17 16 Duan 18 17 Chang 19 17 - 20 19 - 21 20 - 22 21 - 23 22 - 24 23 - 25 24 - 26 25 Duan 27 26 - 28 27 Duan 29 28 - 30 29 Chang 31 28 - 32 31 Chang 33 32 - 34 32 - 35 34 - 36 ...
output:
YES 85 81 105 107 103 117 172 168 275 273 333 321 384 369 327 314 463 433 429 437 588 543 639 667 1273 1167 1375 1160 1176 1117 995 1021 929 926 1059 832 1242 1196 1328 1329 1259 1254 1213 1194 1275 1150 1689 1521 1620 1424 1229 1226 1277 1134 1099 915 1237 1218 1358 1316 1350 1284 2524 2462 2335 21...
result:
ok Correct.
Test #8:
score: 0
Accepted
time: 59ms
memory: 16152kb
input:
100000 2 1 - 3 2 - 4 3 - 5 4 - 6 5 Duan 7 6 - 8 7 - 9 8 - 10 9 Chang 11 10 - 12 11 Duan 13 12 Chang 14 13 - 15 14 Duan 16 15 Chang 17 16 - 18 17 - 19 18 Duan 20 19 - 21 20 - 22 21 - 23 22 Chang 24 23 - 25 24 Duan 26 25 - 27 26 Chang 28 27 - 29 28 - 30 29 - 31 30 Duan 32 31 - 33 32 - 34 33 - 35 34 - ...
output:
YES 69 68 120 118 237 227 225 221 265 266 323 314 309 304 346 343 352 345 338 341 350 347 401 392 439 436 471 469 474 473 472 463 482 480 499 495 483 477 570 567 613 604 588 584 577 576 744 738 743 739 732 730 851 848 841 809 886 881 930 911 951 947 1029 1007 1002 964 958 946 919 914 942 939 959 952...
result:
ok Correct.
Test #9:
score: 0
Accepted
time: 44ms
memory: 16544kb
input:
100000 2 1 - 3 2 - 4 3 - 5 4 - 6 5 Duan 7 6 - 8 7 - 9 8 Chang 10 9 - 11 10 Duan 12 11 - 13 12 Chang 14 13 Duan 15 14 - 16 15 Chang 17 16 - 18 17 Duan 19 18 - 20 19 Chang 21 20 Duan 22 21 Chang 23 22 - 24 23 Duan 25 24 Chang 26 25 Duan 27 26 - 28 27 - 29 28 Chang 30 29 Duan 31 30 Chang 32 31 - 33 32 ...
output:
YES 239 238 274 272 344 343 416 415 433 432 478 477 515 512 544 539 582 579 633 631 711 700 724 717 730 719 787 784 782 780 772 773 783 777 830 831 821 824 816 810 845 849 860 858 872 868 895 897 894 876 871 873 936 929 999 986 984 981 980 976 966 964 955 950 967 958 977 968 997 996 995 993 1039 103...
result:
ok Correct.
Test #10:
score: 0
Accepted
time: 36ms
memory: 17628kb
input:
100000 2 1 - 3 2 - 4 3 - 5 4 - 6 5 - 7 6 - 8 7 - 9 8 - 10 9 - 11 10 - 12 11 - 13 12 - 14 13 - 15 14 - 16 15 - 17 16 - 18 17 - 19 18 - 20 19 - 21 20 - 22 21 - 23 22 - 24 23 - 25 24 - 26 25 - 27 26 - 28 27 - 29 28 - 30 29 - 31 30 - 32 31 - 33 32 - 34 33 - 35 34 - 36 35 - 37 36 - 38 37 - 39 38 - 40 39 ...
output:
YES 4986 4915 6738 6570 14195 13597 22308 22019 31800 31792 38186 38225 43898 43803 41864 41995 42725 42327 43871 43807 43953 43542 46356 46361 47755 47608 47521 46932 46885 44955 48399 48486 50116 49839 49912 49668 54823 53355 54714 54273 54239 53853 52947 52524 57456 55640 58348 58053 59658 59228 ...
result:
ok Correct.
Test #11:
score: 0
Accepted
time: 52ms
memory: 15836kb
input:
100000 2 1 - 3 1 - 4 2 - 5 1 - 6 1 - 7 2 Duan 8 4 - 9 1 - 10 1 - 11 2 - 12 2 - 13 2 - 14 6 - 15 1 - 16 6 - 17 1 - 18 5 - 19 1 - 20 1 - 21 2 - 22 8 - 23 6 - 24 1 - 25 4 Duan 26 1 - 27 10 - 28 1 - 29 8 - 30 5 - 31 7 - 32 2 - 33 3 - 34 12 - 35 3 - 36 1 - 37 12 - 38 8 - 39 8 - 40 1 - 41 4 - 42 16 - 43 8...
output:
YES 34242 34406 14906 23870 28768 79207 50509 68052 70759 32304 70523 36687 36153 68751 47669 3567 18177 70173 50978 58218 27598 56574 46683 47073 79895 6904 85751 4139 83196 17677 65881 90916 44928 67031 49996 25922 28068 95211 43712 69374 84697 19260 32128 70765 30451 79850 92289 12144 99611 51006...
result:
ok Correct.
Test #12:
score: 0
Accepted
time: 52ms
memory: 15860kb
input:
100000 2 1 - 3 1 - 4 1 - 5 1 - 6 1 - 7 1 - 8 1 - 9 1 - 10 3 - 11 1 - 12 2 - 13 2 - 14 2 - 15 1 - 16 2 - 17 2 - 18 1 - 19 1 - 20 1 - 21 2 - 22 1 - 23 2 - 24 2 - 25 1 - 26 1 - 27 4 - 28 1 - 29 2 - 30 3 - 31 1 - 32 10 - 33 6 - 34 4 - 35 1 - 36 2 Duan 37 1 - 38 4 - 39 10 - 40 1 - 41 1 - 42 3 - 43 6 - 44...
output:
YES 15102 66302 37177 40113 67735 67876 70745 98880 75547 84740 88398 71830 62593 85699 71970 21755 94458 6455 74239 39981 71421 13515 37672 71660 90862 91238 42744 19470 13573 72747 10218 81223 15063 87004 19357 68085 44673 6427 92721 4280 17731 33161 45357 358 49326 65914 45470 93622 91832 15964 9...
result:
ok Correct.
Test #13:
score: 0
Accepted
time: 45ms
memory: 16468kb
input:
100000 2 1 Duan 3 1 Duan 4 1 Duan 5 1 Duan 6 1 Duan 7 1 - 8 1 Duan 9 1 Duan 10 1 - 11 1 Duan 12 1 - 13 1 Duan 14 1 Duan 15 1 Duan 16 1 Duan 17 1 Duan 18 2 - 19 1 Duan 20 1 Duan 21 2 - 22 2 Duan 23 1 Duan 24 1 Duan 25 1 Duan 26 1 Duan 27 2 Duan 28 1 Duan 29 2 Duan 30 1 Duan 31 2 Duan 32 1 - 33 1 Duan...
output:
YES 63894 95158 88697 88086 85544 75216 73765 72642 72241 69085 14063 61983 55203 54430 50491 41588 40110 38849 34955 27596 15274 1136 10786 18595 21493 24025 25178 30164 30800 40282 50699 52476 59910 76452 79238 86389 91441 96792 30463 1197 34098 46043 47433 49151 56601 57549 59254 65754 66989 8754...
result:
ok Correct.
Test #14:
score: 0
Accepted
time: 50ms
memory: 15980kb
input:
100000 2 1 - 3 1 - 4 1 - 5 1 - 6 1 - 7 1 - 8 1 - 9 1 - 10 1 - 11 1 - 12 1 - 13 1 Duan 14 1 - 15 1 - 16 1 - 17 1 - 18 1 - 19 1 - 20 1 - 21 1 - 22 1 - 23 1 - 24 1 - 25 1 - 26 1 - 27 1 - 28 1 - 29 1 Duan 30 1 - 31 1 - 32 2 Duan 33 1 - 34 1 - 35 1 Duan 36 1 - 37 1 - 38 1 - 39 1 - 40 1 - 41 1 - 42 1 - 43...
output:
YES 51260 62964 64799 73003 87232 98672 31245 38059 47626 58383 78385 82570 84269 91105 67893 90700 95599 97507 51711 96567 84425 2480 90521 97467 97387 3614 52378 20327 24851 31941 34768 35502 36133 37919 38081 41305 46820 47134 51834 18144 52602 53825 60150 63344 65516 68450 79862 84495 88745 9084...
result:
ok Correct.
Test #15:
score: 0
Accepted
time: 44ms
memory: 15868kb
input:
100000 2 1 Duan 3 1 - 4 1 - 5 1 Duan 6 1 - 7 1 - 8 1 - 9 1 - 10 1 - 11 1 - 12 1 - 13 1 - 14 1 - 15 1 - 16 1 - 17 1 - 18 1 - 19 1 - 20 1 - 21 1 - 22 1 - 23 1 - 24 1 - 25 1 - 26 1 - 27 1 - 28 1 - 29 1 - 30 1 - 31 1 - 32 1 - 33 1 Duan 34 1 - 35 1 - 36 1 - 37 1 - 38 1 - 39 1 - 40 1 - 41 1 - 42 1 - 43 1 ...
output:
YES 51853 97806 89831 81679 70717 62015 60751 59449 56321 54934 54125 53261 24271 49313 49018 46496 43803 39709 39458 38753 38738 38484 37384 32530 58304 99744 99690 97190 93135 88437 76662 73977 73029 71317 68370 61172 61007 58424 18859 57761 57280 55259 54712 46485 44356 43694 39921 34688 33247 30...
result:
ok Correct.
Test #16:
score: 0
Accepted
time: 43ms
memory: 15924kb
input:
100000 2 1 Duan 3 1 Duan 4 1 - 5 1 Duan 6 1 - 7 1 Duan 8 1 Duan 9 1 Duan 10 1 Duan 11 1 - 12 1 - 13 1 - 14 1 Duan 15 1 Duan 16 1 Duan 17 1 - 18 1 Duan 19 1 Duan 20 1 Duan 21 1 - 22 1 - 23 1 Duan 24 1 Duan 25 1 Duan 26 1 - 27 1 - 28 1 Duan 29 1 Duan 30 1 - 31 1 Duan 32 1 Duan 33 1 - 34 1 Duan 35 1 - ...
output:
YES 82705 336 60220 72014 80211 95022 93125 94029 59250 85950 77242 89854 56243 61755 80147 86382 86818 91748 37709 408 87876 89771 83493 452 97158 481 92488 614 95750 824 30379 31237 31218 31062 31048 30964 30860 30850 30689 30666 30642 30487 31450 30316 30298 30147 29890 29748 29745 29652 29648 29...
result:
ok Correct.
Test #17:
score: 0
Accepted
time: 31ms
memory: 13244kb
input:
100000 2 1 - 3 1 - 4 2 - 5 2 - 6 2 Duan 7 3 - 8 1 - 9 1 - 10 6 - 11 3 - 12 2 - 13 7 - 14 1 - 15 9 - 16 11 - 17 13 - 18 9 - 19 16 - 20 19 - 21 8 - 22 5 - 23 14 - 24 21 - 25 21 - 26 16 - 27 5 - 28 5 - 29 19 - 30 8 - 31 24 - 32 30 - 33 12 Duan 34 9 - 35 12 Duan 36 6 - 37 15 - 38 26 - 39 29 - 40 13 - 41...
output:
NO
result:
ok Correct.
Test #18:
score: -100
Wrong Answer
time: 80ms
memory: 16352kb
input:
100000 2 1 Duan 3 2 Duan 4 3 - 5 3 Duan 6 4 - 7 4 Duan 8 3 Duan 9 2 - 10 4 Duan 11 8 Duan 12 6 - 13 3 Duan 14 6 Duan 15 7 Duan 16 6 Duan 17 14 Tong 18 7 - 19 16 Duan 20 14 Duan 21 12 Duan 22 20 Duan 23 14 Duan 24 19 - 25 2 Duan 26 22 - 27 24 Duan 28 8 Duan 29 4 Duan 30 23 Duan 31 24 Duan 32 23 Duan ...
output:
YES 94206 32087 86101 44400 38129 24653 83167 86393 56505 19062 63492 57948 65030 61940 53403 26407 82477 45835 94475 18036 82278 8076 96418 49061 35535 17844 80815 22654 79364 67385 60352 26598 88811 20526 77251 83985 70144 26473 14708 1615 77049 34973 41105 22442 86702 39057 82616 30892 47754 8107...
result:
wrong output format Unexpected end of file - int32 expected