QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#178191 | #5506. Hyperloop | real_sigma_team# | WA | 204ms | 3812kb | C++20 | 1.6kb | 2023-09-13 19:21:11 | 2023-09-13 19:21:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, ll>>> g(n);
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<pair<ll, int>> dist(n, {1e18, 1e9});
set<pair<pair<ll, int>, int>> st;
dist[n - 1] = {0, 1};
st.emplace(dist[n - 1], n - 1);
while (st.size()) {
int u = st.begin()->second;
st.erase(st.begin());
for (auto [to, w] : g[u]) {
pair<ll, int> pp = {dist[u].first + w, dist[u].second + 1};
if (dist[to] > pp) {
st.erase({dist[to], to});
dist[to] = pp;
st.emplace(dist[to], to);
}
}
}
vector<int> ans = {0};
for (int u = 0; u != n - 1; ) {
int v = n;
for (auto [to, w] : g[u]) {
pair<ll, int> pp = {dist[u].first - w, dist[u].second - 1};
if (dist[to] == pp) v = min(v, to);
}
ans.push_back(v);
u = v;
}
cout << ans.size() << '\n';
for (auto to : ans) cout << to + 1 << ' ';
cout << '\n';
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: -100
Wrong Answer
time: 204ms
memory: 3812kb
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:
wrong answer Contestant's path is not optimal lexicographically (test case 3)