QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720991 | #7883. Takeout Delivering | coolarec | WA | 380ms | 65240kb | C++20 | 2.2kb | 2024-11-07 14:55:04 | 2024-11-07 14:55:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls first
#define rs second
void solve() {
int n, m;
cin >> n >> m;
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>>
pq;
vector<vector<pair<int, int>>> e(n + 1);
for (int i = 1; i <= m; i++) {
int x, y, w;
cin >> x >> y >> w;
pq.push({w, x, y});
e[x].push_back({y, w});
e[y].push_back({x, w});
}
vector<int> p(n + 1), dis(n + 1, 0);
iota(p.begin(), p.end(), 0);
dis[1] = 0;
function<int(int)> find = [&](int x) {
return p[x] == x ? x : p[x] = find(p[x]);
};
vector<int> sta(n + 1);
function<void(int, int)> change = [&](int u, int w) {
if (dis[u] || u == 1)
return;
dis[u] = w;
for (auto [v, ww] : e[u]) {
if (sta[v])
change(v, w);
}
};
while (pq.size()) {
auto [w, x, y] = pq.top();
pq.pop();
sta[x] = sta[y] = 1;
p[find(x)] = find(y);
if (find(x) == find(1) || find(y) == find(1)) {
change(x, w), change(y, w);
}
// for (int i = 1; i <= n; i++) {
// cout << dis[i] << ' ';
// }
// cout << '\n';
}
auto check = [&](int x) {
queue<int> qu;
qu.push(n);
vector<int> vis(n + 1);
iota(p.begin(), p.end(), 0);
vis[n] = 1;
while (qu.size()) {
auto u = qu.front();
qu.pop();
for (auto [v, w] : e[u]) {
if (vis[v])
continue;
if (w + dis[v] > x)
continue;
vis[v] = 1;
p[find(v)] = find(u);
qu.push(v);
}
}
return find(1) == find(n);
};
int l = 1, r = 2e9 + 1;
while (l < r) {
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
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: 380ms
memory: 65240kb
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:
1999918409
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1999918409'