QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89994 | #5506. Hyperloop | fstqwq | WA | 190ms | 6124kb | C++20 | 1.9kb | 2023-03-21 21:54:58 | 2023-03-21 21:55:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
const int N = 1e5 + 5;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m;
vector < pair <int, int>> E[N];
pair <LL, int> dis[N];
bool ok[N];
struct node {
int x;
pair <LL, int> d;
bool operator < (const node &a) const {
return d > a.d;
}
};
pair <LL, int> operator + (const pair <LL, int>& a, const pair <LL, int>& b) {
return {a.first + b.first, a.second + b.second};
}
void work () {
for (int i = 1; i <= n; i++) E[i].clear();
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
E[u].push_back({v, w});
E[v].push_back({u, w});
}
fill(dis + 1, dis + n + 1, make_pair (INF, 0));
dis[1] = {0ll, 0};
{
priority_queue <node> q;
q.push({1, dis[1]});
while (!q.empty()) {
auto [x, d] = q.top(); q.pop();
if (dis[x] != d) continue;
for (auto [v, w] : E[x]) {
if (dis[v] > d + make_pair((LL)w, 1)) {
dis[v] = d + make_pair((LL)w, 1);
q.push({v, dis[v]});
}
}
}
}
fill(ok + 1, ok + n + 1, 0);
{
queue <int> q;
ok[n] = 1;
q.push(n);
while (!q.empty()) {
int x = q.front(); q.pop();
for (auto [v, w] : E[x]) {
if (!ok[v] && dis[x] == dis[v] + make_pair((LL)w, 1)) {
ok[v] = 1;
q.push(v);
}
}
}
}
vector <int> ans = {1};
while (ans.back() != n) {
int x = ans.back();
pair <int, int> best{-1, -1};
for (auto [v, w] : E[x]) {
if (ok[v] && dis[v] == dis[x] + make_pair((LL)w, 1)) {
best = max(best, make_pair(w, v));
}
}
ans.push_back(best.second);
}
printf("%d\n", (int) ans.size());
for (auto i : ans) printf("%d ", i);
printf("\n");
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
cin >> T;
for (int ca = 1; ca <= T; ca ++)
work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 6040kb
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 3 4 5 1 2 5 3 6
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 190ms
memory: 6124kb
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:
wrong answer Contestant's path is not optimal lexicographically (test case 2)