QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721077 | #7883. Takeout Delivering | coolarec | WA | 0ms | 3820kb | C++20 | 2.4kb | 2024-11-07 15:10:33 | 2024-11-07 15:10:34 |
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), pp(n + 1), dis(n + 1, 1e18);
iota(p.begin(), p.end(), 0);
iota(pp.begin(), pp.end(), 0);
dis[1] = 0;
function<int(int)> find = [&](int x) {
return p[x] == x ? x : p[x] = find(p[x]);
};
function<int(int)> findpp = [&](int x) {
return pp[x] == x ? x : pp[x] = find(pp[x]);
};
vector<int> sta(n + 1);
function<void(int, int, int)> change = [&](int u, int w, int root) {
if (dis[u] != 1e18 || u == 1)
return;
dis[u] = w;
for (auto [v, ww] : e[u]) {
if (sta[v] && find(v) == find(root))
change(v, w, root);
}
};
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)) {
change(x, w, x);
}
// cerr << x << ' ' << y << ' ' << w << '\n';
// 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();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3820kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
6
result:
wrong answer 1st numbers differ - expected: '5', found: '6'