QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640601 | #7883. Takeout Delivering | Star_s | WA | 342ms | 33288kb | C++14 | 2.5kb | 2024-10-14 14:38:28 | 2024-10-14 14:38:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// using ll = long long;
#define int long long
int n, m;
int i, j, k;
vector<pair<int, int> > v[300010];
int dis1[300010], dis2[300010];//1:1-x; 2:n-x
int vis[300010];
struct Node {
int u, dis;
Node(int u, int dis) : u(u), dis(dis) {}
bool operator < (const Node& rhs) const {
return dis < rhs.dis;
}
};
void dij1(int s) {
Node nn = Node(s, 0);
priority_queue<Node> pq;
pq.push(nn);
while(!pq.empty()) {
Node t = pq.top();
pq.pop();
int u = t.u, dis = t.dis;
if(vis[u]) continue;
vis[u] = 1;
for(auto p : v[u]) {
int v = p.first, w = p.second;
if(dis1[v] > max(dis1[u], w)) {
dis1[v] = max(dis1[u], w);
pq.push(Node(v, dis1[v]));
}
}
}
}
void dij2(int s) {
Node nn = Node(s, 0);
priority_queue<Node> pq;
pq.push(nn);
while(!pq.empty()) {
Node t = pq.top();
pq.pop();
int u = t.u, dis = t.dis;
if(vis[u]) continue;
vis[u] = 1;
for(auto p : v[u]) {
int v = p.first, w = p.second;
if(dis2[v] > max(dis2[u], w)) {
dis2[v] = max(dis2[u], w);
pq.push(Node(v, dis2[v]));
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
for(i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
v[a].push_back({b, c});
v[b].push_back({a, c});
}
memset(dis1, 0x3f, sizeof(dis1));
memset(dis2, 0x3f, sizeof(dis2));
memset(vis, 0, sizeof(vis));
dis1[1] = 0;
dis2[n] = 0;
dij1(1);
memset(vis, 0, sizeof(vis));
dij2(n);
// for (i = 1; i <= n; i ++)
// {
// cout << dis1[i] << " " << dis2[i] << "\n";
// }
int ans = 0x3f3f3f3f;
for (i = 1; i <= n; i ++)
{
for (j = 0; j < v[i].size(); j ++)
{
int x = v[i][j].first, y = v[i][j].second;
int ans1 = max(dis1[i], dis2[x]);
int ans2 = max(dis1[x], dis2[i]);
if (ans1 <= y) ans = min(ans, ans1 + y);
if (ans2 <= y) ans = min(ans, ans2 + y);
// cout << i << " " << x << " " << y << " " << ans1 << " " << ans2 << "\n";
// ans = min(ans, min(ans1, ans2));
}
}
cout << ans << "\n";
}
signed main() {
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 17648kb
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: 342ms
memory: 33288kb
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:
1061109567
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1061109567'