QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274433 | #7883. Takeout Delivering | zhensuan | WA | 90ms | 22768kb | C++20 | 2.0kb | 2023-12-03 15:32:39 | 2023-12-03 15:32:39 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
vector<pair<int, int>>e[maxn];
bool vis[maxn], vis1[maxn];
int dis[maxn];
int mx[maxn];
struct node1 {
int id, mx;
friend bool operator <(node1 a, node1 b) {
return a.mx > b.mx;
}
};
void bfs() {
priority_queue<node1>q;
mx[1] = 0;
q.push({ 1,0 });
while (!q.empty()) {
auto [u, _] = q.top();
q.pop();
if (vis1[u])continue;
vis1[u] = true;
for (auto [v, w] : e[u]) {
if (mx[v] > max(mx[u], w)) {
mx[v] = max(mx[u], w);
q.push({ v,mx[v] });
}
}
}
}
struct node {
int id;
int x, y;
friend bool operator <(node a, node b) {
return a.x + a.y > b.x + b.y;
}
};
void dij() {
priority_queue<node>q;
dis[1] = 0;
q.push({ 1,0,0 });
while (!q.empty()) {
auto [u, x, y] = q.top();
q.pop();
if (vis[u])continue;
vis[u] = true;
for (auto [v, w] : e[u]) {
if (w >= y) {
if (dis[v] > w + mx[u]) {
dis[v] = w + mx[u];
q.push({ v, max(w, mx[u]), min(w, mx[u]) });
}
} else {
if (dis[v] > dis[u]) {
dis[v] = dis[u];
q.push({ v,x,y });
}
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
int res = 2e9 + 7;
memset(dis, 0x3f, sizeof dis);
memset(mx, 0x3f, sizeof mx);
for (int i = 1;i <= m;i++) {
int u, v, w;
cin >> u >> v >> w;
e[u].push_back({ v,w });
e[v].push_back({ u,w });
}
bfs();
dij();
cout << dis[n] << endl;
}
signed main() {
int t = 1;
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13396kb
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: 90ms
memory: 22768kb
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'