QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91079 | #5506. Hyperloop | skittles1412 | ML | 265ms | 3708kb | C++17 | 3.6kb | 2023-03-27 01:16:47 | 2023-03-27 01:16:50 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
vector<long> dijkstra(int src, const vector<vector<pair<int, int>>>& graph) {
int n = sz(graph);
vector<long> dist(n, 1e18);
min_pq<pair<long, int>> pq;
auto push = [&](int u, long d) -> void {
if (d < dist[u]) {
dist[u] = d;
pq.emplace(d, u);
}
};
push(src, 0);
while (sz(pq)) {
auto [d, u] = pq.top();
pq.pop();
for (auto& [v, w] : graph[u]) {
push(v, d + w);
}
}
return dist;
}
vector<vector<pair<int, int>>> filter_sp(int n,
const vector<long>& dist,
vector<vector<pair<int, int>>> graph) {
for (int i = 0; i < n; i++) {
auto& a = graph[i];
a.erase(remove_if(begin(a), end(a),
[&](const auto& e) -> bool {
auto& [v, w] = e;
return dist[i] + w != dist[v];
}),
a.end());
}
return graph;
}
struct S {
static constexpr int bsize = 250;
array<uint16_t, bsize> small {};
basic_string<uint16_t> large;
void clear() {
large.clear();
}
void insert(int x) {
if (x < bsize) {
small[bsize - x - 1]++;
} else {
large.insert(upper_bound(begin(large), end(large), x, greater<>()), x);
}
}
bool operator<(const S& s) const {
if (large == s.large) {
return small < s.small;
}
return large < s.large;
}
};
void solve() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> graph(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
graph[u].emplace_back(v, w);
graph[v].emplace_back(u, w);
}
auto dist = dijkstra(0, graph);
graph = filter_sp(n, dist, graph);
int ord[n];
iota(ord, ord + n, 0);
sort(ord, ord + n, [&](int a, int b) -> bool {
return dist[a] < dist[b];
});
S dp[n];
int from[n];
for (auto& a : ord) {
for (auto& [v, w] : graph[a]) {
auto tmp = dp[a];
tmp.insert(w);
if (dp[v] < tmp) {
dp[v] = tmp;
from[v] = a;
}
}
dp[a].clear();
}
vector<int> ans;
int u = n - 1;
while (true) {
ans.push_back(u);
if (!u) {
break;
}
u = from[u];
}
reverse(begin(ans), end(ans));
cout << sz(ans) << endl;
for (int i = 0; i < sz(ans); i++) {
cout << ans[i] + 1 << " \n"[i == sz(ans) - 1];
}
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
int tcs;
cin >> tcs;
while (tcs--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3292kb
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: 265ms
memory: 3708kb
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok correct (600 test cases)
Test #3:
score: -100
Memory Limit Exceeded
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...