QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344221 | #5506. Hyperloop | ucup-team1198# | ML | 227ms | 5896kb | C++20 | 4.6kb | 2024-03-03 19:19:02 | 2024-03-03 19:19:02 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
struct Node {
int val;
int left, right;
Node(int val): val(val), left(-1), right(-1) {}
Node() {}
};
Node nodes[5'120'000];
int nodes_cnt = 0;
int node(int val) {
nodes[nodes_cnt] = Node(val);
++nodes_cnt;
return nodes_cnt - 1;
}
int val(int T) {
return T == -1 ? 0 : nodes[T].val;
}
int get_left(int T) {
return T == -1 ? -1 : nodes[T].left;
}
int get_right(int T) {
return T == -1 ? -1 : nodes[T].right;
}
int add(int T, int left, int right, int x) {
int ans = node(val(T) + 1);
nodes[ans].left = get_left(T);
nodes[ans].right = get_right(T);
if (left + 1 == right)
return ans;
int mid = (left + right) / 2;
if (x < mid)
nodes[ans].left = add(get_left(T), left, mid, x);
else
nodes[ans].right = add(get_right(T), mid, right, x);
return ans;
}
void go_down(int T, int left, int right, vector<pair<int, int>>& to) {
if (T == -1)
return;
if (left + 1 == right) {
to.emplace_back(left, nodes[T].val);
return;
}
int mid = (left + right) / 2;
go_down(nodes[T].right, mid, right, to);
go_down(nodes[T].left, left, mid, to);
}
bool cmp(const vector<pair<int, int>>& first, const vector<pair<int, int>>& second) {
int i = 0, takeni = 0;
int j = 0, takenj = 0;
while (i < first.size() && j < second.size()) {
if (first[i].first != second[j].first) {
return first[i].first > second[j].first;
}
int take = min(first[i].second - takeni, second[j].second - takenj);
takeni += take;
takenj += take;
if (first[i].second == takeni) {
takeni = 0;
++i;
}
if (second[j].second == takenj) {
takenj = 0;
++j;
}
}
// the same
if (i == first.size() && j == second.size())
return false;
// first is prefix of second
if (i == first.size())
return false;
// second is prefix of first
return true;
}
const int INF = 1e5;
const int MAXN = 100100;
vector<pair<int, int>> G[MAXN];
vector<pair<int, int>> kek;
vector<pair<int, int>> lol;
const int MX = 50'050;
void solve() {
int n, m;
cin >> n >> m;
nodes_cnt = 0;
for (int i = 0; i < m; ++i) {
int u, v, w;
cin >> u >> v >> w;
--u; --v;
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
vector<int> dist(n, INF);
dist[0] = 0;
set<pair<int, int>> Q;
vector<int> order;
Q.emplace(0, 0);
while (!Q.empty()) {
int v = Q.begin()->second;
order.emplace_back(v);
Q.erase(Q.begin());
for (auto [u, w] : G[v]) {
if (dist[u] > dist[v] + w) {
Q.erase(make_pair(dist[u], u));
dist[u] = dist[v] + w;
Q.emplace(dist[u], u);
}
}
}
vector<int> dps(n, -2);
vector<int> par(n, -1);
dps[0] = -1;
for (int v : order) {
for (auto [u, w] : G[v]) {
if (dist[u] + w == dist[v]) {
// cur is lol
int var = add(dps[u], 0, MX, w);
kek.clear();
go_down(var, 0, MX, kek);
if (dps[v] == -2) {
swap(lol, kek);
par[v] = u;
dps[v] = var;
} else {
if (cmp(kek, lol)) {
swap(lol, kek);
par[v] = u;
dps[v] = var;
}
}
}
}
lol.clear();
}
int cur = n - 1;
vector<int> ans;
while (cur != 0) {
ans.emplace_back(cur);
cur = par[cur];
}
ans.emplace_back(0);
reverse(ans.begin(), ans.end());
cout << ans.size() << '\n';
for (int x : ans)
cout << x + 1 << ' ';
cout << '\n';
for (int i = 0; i < n; ++i) {
G[i].clear();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5648kb
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: 227ms
memory: 5896kb
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: -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...
output:
35000 1 24721 24696 24717 24804 24757 24988 24231 25030 24601 94061 24443 24448 24563 25096 43056 43055 43054 43053 43052 43051 43050 43049 43048 43047 43046 43045 43044 43043 43042 43041 43040 43039 43038 43037 43036 43035 43034 43033 43032 43031 43030 43029 43028 43027 43026 43025 43024 43023 4302...