QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733914 | #7883. Takeout Delivering | XiaoYang3 | WA | 143ms | 42556kb | C++23 | 1.9kb | 2024-11-10 22:02:40 | 2024-11-10 22:02:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const int N = 2e6 + 5;
const ll P = 1e9 + 7;
ll m, n, q, tot;
vector<pii> ve[N];
struct node {
ll x, y, w;
} st[N];
void solve() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> st[i].x >> st[i].y >> st[i].w;
ve[st[i].x].push_back({st[i].y, st[i].w});
ve[st[i].y].push_back({st[i].x, st[i].w});
}
vector<ll> dis1(n + 2);
vector<ll> dis2(n + 2);
auto dij = [&](int now) -> void {
vector<int> v(n + 2);
vector<ll> dis(n + 2, 1e12);
dis[now] = 0;
priority_queue<pii, vector<pii>, greater<pii>> q;
q.push({0, now});
while (q.size()) {
auto [d, x] = q.top();
q.pop();
if (v[x]) {
continue;
}
v[x] = 1;
for (auto [y, w] : ve[x]) {
if (dis[y] > max(d, w)) {
dis[y] = min(dis[y], max(d, w));
q.push({dis[y], y});
}
}
}
if (now == 1) {
for (int i = 1; i <= n; i++) {
dis1[i] = dis[i];
}
} else {
for (int i = 1; i <= n; i++) {
dis2[i] = dis[i];
}
}
};
dij(1);
dij(n);
ll ans = 1e12;
for (int i = 1; i <= m; i++) {
auto [x, y, w] = st[i];
// cout << dis1[x] << ' ' << dis2[y] << '\n';
ll sum = w + dis1[x] + dis2[y];
if(x==1||x==n||y==1||y==n){continue;}
ans = min(ans, sum - min({w, dis1[x], dis2[y]}));
sum = w + dis1[y] + dis2[x];
ans = min(ans, sum - min({w, dis1[y], dis2[x]}));
}
cout << ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 143ms
memory: 42556kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
1372263078
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1372263078'