QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91260 | #5506. Hyperloop | Denisov | AC ✓ | 608ms | 56932kb | C++20 | 4.6kb | 2023-03-28 04:06:23 | 2023-03-28 04:06:24 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
inline bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef LOCAL
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif // LOCAL
const int max_n = -1, inf = 1000111222;
using base = pair<unsigned short, unsigned short>;
inline vector <base> add(vector <base> &a, int x) {
for (int i = 0; i < len(a); i++) {
if (a[i].first == x) {
auto b = a;
++b[i].second;
return b;
}
}
vector <base> new_a(len(a) + 1);
int cnt = 0;
for (int i = 0; i < len(a); ) {
if (a[i].first < x) {
new_a[cnt++] = {x, 1};
x = 0;
}
else {
new_a[cnt++] = a[i];
++i;
}
}
if (cnt < len(a) + 1) {
new_a[cnt] = {x, 1};
}
return new_a;
}
inline bool check (vector <base> &a, vector <base> &b) { /// b > a
for (int i = 0; i < min(len(a), len(b)); i++) {
if (a[i].first < b[i].first) {
return true;
}
if (a[i].first > b[i].first) {
return false;
}
if (a[i].second < b[i].second) {
return true;
}
if (a[i].second > b[i].second) {
return false;
}
}
return len(a) < len(b);
}
inline void test_case () {
int n, m;
cin >> n >> m;
vector <pair<pii, int> > e(m + m);
for (int i = 0; i < m; i++) {
cin >> e[i].first.first >> e[i].first.second >> e[i].second;
--e[i].first.first;
--e[i].first.second;
e[m + i] = {{e[i].first.second, e[i].first.first}, e[i].second};
}
m += m;
sort(all(e));
vector <int> p(n);
for (int i = 0, j = 0; i < n; i++) {
while (j < m && e[j].first.first < i) {
++j;
}
p[i] = j;
}
priority_queue <pii> q;
vector <int> d(n, inf);
d[0] = 0;
q.push({0, 0});
while (!q.empty()) {
int v, dist;
tie(dist, v) = q.top();
q.pop();
if (-dist > d[v]) {
continue;
}
for (int i = p[v]; i < m; i++) {
if (e[i].first.first != v) break;
int to = e[i].first.second;
int len = e[i].second;
if (umin(d[to], d[v] + len)) {
q.push({-d[to], to});
}
}
}
vector <int> order(n);
iota(all(order), 0);
sort(all(order), [&] (int a, int b) {
return d[a] > d[b];
});
vector <vector <base> > nice(n);
vector <bool> good(n);
vector <int> go(n);
good[n - 1] = true;
for (int v : order) {
if (d[v] > d[n - 1]) {
continue;
}
for (int i = p[v]; i < m; i++) {
if (e[i].first.first != v) {
break;
}
int to = e[i].first.second;
int len = e[i].second;
if (d[to] == d[v] + len && good[to]) {
auto gg = add(nice[to], len);
if (!good[v]) {
good[v] = true;
nice[v] = gg;
go[v] = to;
}
else if (check(nice[v], gg)){
nice[v] = gg;
go[v] = to;
}
}
}
}
vector <int> ans;
int v = 0;
while (v != n - 1) {
ans.pb(v);
v = go[v];
}
ans.pb(n - 1);
cout << len(ans) << '\n';
for (auto &i : ans) {
cout << i + 1 << ' ';
}
cout << '\n';
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for (int test = 1; test <= t; test++) {
test_case();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3412kb
input:
2 4 6 1 2 1 1 3 2 2 3 1 2 4 2 3 4 1 1 4 4 6 11 1 2 9 2 3 12 3 4 3 4 5 5 5 6 10 6 1 22 2 4 9 3 6 1 4 6 5 2 5 2 3 5 8
output:
3 1 2 4 5 1 2 5 3 6
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 321ms
memory: 3908kb
input:
600 320 1547 204 81 13768 232 97 9939 97 249 3719 201 109 14322 183 132 40881 142 143 1 275 186 24548 18 236 7907 30 317 11845 131 130 1 311 300 11704 141 92 41925 174 191 32128 119 120 1 184 183 1 310 309 1 283 270 25477 233 141 36076 212 92 13770 307 110 40656 218 137 14033 180 85 41892 200 199 44...
output:
184 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok correct (600 test cases)
Test #3:
score: 0
Accepted
time: 446ms
memory: 17904kb
input:
4 100000 220000 48940 43355 42347 77914 77913 1 45236 82683 42904 22563 16038 34866 81537 81538 43088 49803 51485 25497 63071 25523 14336 44102 39850 43782 13607 92386 16724 98711 73651 46840 17775 16801 28765 5757 98829 13508 85095 48444 1 9198 43003 32678 14461 14462 1 20245 48742 18138 89120 8911...
output:
35000 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 correct (4 test cases)
Test #4:
score: 0
Accepted
time: 608ms
memory: 56932kb
input:
4 100000 160000 5533 94547 28459 14992 20984 20548 70133 92512 27510 9013 9012 304 13621 40571 47787 305 306 262 6987 6988 135 16234 16992 40656 26246 49196 27701 19103 60272 44055 91532 91531 38290 70778 68341 35147 32524 32523 13 85786 50300 40970 49277 29735 13942 43446 34519 42455 77623 17031 34...
output:
316 1 2 3 4 5 6 97410 97409 26434 26435 26436 26437 98883 1370 1369 1368 92157 92158 4815 4816 4817 4818 50181 16985 89607 89608 24674 16979 16980 38428 13232 13233 13234 13664 13663 95009 7166 7165 7164 7163 24798 24799 11787 31031 53551 7309 7310 35482 7933 25067 32714 32715 44194 2068 72216 79593...
result:
ok correct (4 test cases)
Test #5:
score: 0
Accepted
time: 534ms
memory: 17540kb
input:
4 100000 160000 89517 25671 43802 21059 21058 1 35299 91834 43615 53383 53382 1 27213 39161 17202 10715 4050 30342 44100 44099 1 24162 28648 7378 19022 23084 37734 66056 97934 14651 31566 89391 23215 91038 91037 1 47695 47696 6099 99142 99143 1 83908 73654 15060 15551 22001 8896 55190 55189 1 26536 ...
output:
632 1 94652 1699 1698 1697 31170 31169 31168 31163 5029 31189 31190 31191 31192 2471 2470 2467 2466 2465 2510 2511 2514 2521 2524 71980 74130 74129 99693 84670 84671 71536 30302 30301 30300 30299 30298 30297 30296 30295 30294 30293 30292 30291 30290 30289 30288 30287 30286 30285 26878 35089 70835 38...
result:
ok correct (4 test cases)