QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189840 | #2879. Kaleidoscopic Route | MaGnsi0# | WA | 50ms | 10428kb | C++17 | 1.7kb | 2023-09-28 00:31:58 | 2023-09-28 00:31:59 |
Judging History
answer
/**
* author: MaGnsi0
* created: 27.09.2023 19:16:48
**/
#include <bits/stdc++.h>
using namespace std;
const int OO = 2e9;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> adj(n);
for (int i = 0; i < m; ++i) {
int u, v, c;
cin >> u >> v >> c;
adj[u - 1].emplace_back(v - 1, c);
adj[v - 1].emplace_back(u - 1, c);
}
vector<int> p(n, -1), d(n, OO), diff(n, 0);
set<tuple<int, int, int, int, int>> S;
d[0] = 0, diff[0] = -1 - OO, S.emplace(0, OO + 1, 0, -1, OO);
while (!S.empty()) {
int d_v, diff_v, v, maxe, mine;
tie(d_v, diff_v, v, maxe, mine) = *S.begin();
S.erase(S.begin());
diff_v *= -1;
if (d_v != d[v] || diff_v != diff[v]) {
continue;
}
for (auto [u, c] : adj[v]) {
if (d_v + 1 < d[u]) {
p[u] = v;
d[u] = d_v + 1;
diff[u] = max(maxe, c) - min(mine, c);
S.emplace(d[u], -diff[u], u, max(maxe, c), min(mine, c));
} else if (d_v + 1 == d[u] && diff[u] < max(maxe, c) - min(mine, c)) {
p[u] = v;
d[u] = d_v + 1;
diff[u] = max(maxe, c) - min(mine, c);
S.emplace(d[u], -diff[u], u, max(maxe, c), min(mine, c));
}
};
}
cout << d[n - 1] << "\n";
vector<int> path;
for (int v = n - 1; v != -1; v = p[v]) {
path.push_back(v);
}
reverse(path.begin(), path.end());
for (int v : path) {
cout << v + 1 << " ";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
6 8 1 5 2 5 2 5 3 5 4 1 3 10 3 4 6 4 5 7 4 6 8 2 6 1
output:
3 1 5 4 6
result:
ok 3 6
Test #2:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
10 20 1 9 34 6 3 80 7 3 15 5 4 73 4 1 42 8 6 92 2 10 25 4 3 8 9 3 79 3 1 11 9 2 74 10 1 83 3 2 6 10 3 38 10 4 48 1 5 38 6 2 43 4 2 55 8 7 90 3 5 4
output:
1 1 10
result:
ok 1 0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
24 65 22 11 519 2 4 585 8 17 647 1 11 464 13 4 596 12 10 733 24 21 106 1 14 345 23 5 430 2 3 137 16 7 891 16 4 807 14 3 465 4 22 532 16 9 346 21 8 859 18 15 631 9 5 914 19 17 729 1 2 546 5 15 43 2 12 349 19 9 642 13 3 441 20 15 359 21 11 645 9 14 992 4 23 9 23 9 34 24 16 117 16 18 349 10 22 285 22 5...
output:
2 1 11 24
result:
ok 2 208
Test #4:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
53 123 43 38 999 7 24 718 6 33 393 16 15 734 21 39 604 27 15 828 45 31 747 23 4 538 14 41 224 38 9 756 12 36 574 12 13 624 7 34 649 17 53 309 38 33 825 1 36 273 38 21 81 36 11 680 14 8 649 12 24 346 21 49 921 1 47 612 11 39 648 41 35 271 15 24 36 29 3 980 29 28 295 15 21 236 27 8 853 22 6 532 3 14 9...
output:
2 1 52 53
result:
ok 2 482
Test #5:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
2 1 2 1 33
output:
1 1 2
result:
ok 1 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
123 1032 49 28 6306 70 79 6579 24 47 3306 102 114 7381 78 34 4078 31 92 2591 114 65 7836 92 59 7583 110 51 4384 84 99 439 78 48 77 23 77 6225 96 69 2939 55 112 45 48 29 4735 27 18 4242 117 97 395 71 64 2979 102 36 9531 20 86 7795 11 5 3142 114 107 1188 62 106 6321 6 71 2974 102 96 4240 82 13 7488 95...
output:
2 1 93 123
result:
ok 2 5258
Test #7:
score: 0
Accepted
time: 5ms
memory: 4176kb
input:
1342 23134 757 512 65447 281 782 35017 179 633 86323 707 635 20673 1225 962 76138 986 59 62123 29 482 39870 90 265 65928 572 1028 18186 810 568 89715 469 998 95978 583 641 63660 261 208 37031 775 1131 33707 161 702 33733 1340 726 67611 548 583 9224 1100 208 82846 227 486 60094 1070 565 49959 1285 11...
output:
3 1 669 616 1342
result:
ok 3 93825
Test #8:
score: 0
Accepted
time: 17ms
memory: 6192kb
input:
5313 87123 3239 37 964433 3078 247 435023 1830 493 489819 4478 1661 914186 750 2703 353434 3853 1072 285309 2117 1377 641750 1254 4366 734040 2222 2191 362794 3461 2267 359296 2514 913 627160 878 1006 709645 1767 3791 250153 4845 4041 339269 3270 2061 26968 2421 660 798388 262 1399 974636 5120 4171 ...
output:
3 1 3463 3294 5313
result:
ok 3 878139
Test #9:
score: 0
Accepted
time: 38ms
memory: 8420kb
input:
12313 173254 4620 6513 380927 4465 6551 243296 615 9825 794381 338 11211 368032 4571 9567 634707 3731 7430 87826 8106 7718 998064 4146 7848 922789 3966 1263 331881 9179 646 948846 11893 5020 883102 5612 10513 898068 3451 3435 451139 9640 1947 1353 12271 9668 283149 9742 5631 884826 6837 2449 309976 ...
output:
3 1 1402 3350 12313
result:
ok 3 497061
Test #10:
score: -100
Wrong Answer
time: 50ms
memory: 10428kb
input:
23532 200000 21979 22532 52608855 17378 1428 55313979 12897 6506 2960978 21412 2936 26201355 1327 21400 71454522 6940 9953 7548221 15846 15164 69193724 22756 8774 49306072 10793 7975 94773768 15722 221 88298496 274 22685 29319966 21564 10196 30589888 2895 9073 93905131 8310 22526 13817682 1565 2616 ...
output:
4 1 11388 16361 18380 23532
result:
wrong answer jury has better answer