QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640628 | #7883. Takeout Delivering | Star_s | WA | 243ms | 23476kb | C++14 | 2.5kb | 2024-10-14 14:52:40 | 2024-10-14 14:52:40 |
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 u == rhs.u? dis < rhs.dis : u < rhs.u;
}
};
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, 1e9 + 7, sizeof(dis1));
memset(dis2, 1e9 + 7, 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 = 2e9 + 14;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14096kb
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: 243ms
memory: 23476kb
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:
235802350
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '235802350'