QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657353 | #7883. Takeout Delivering | Zlin05 | RE | 0ms | 7724kb | C++23 | 2.1kb | 2024-10-19 14:37:30 | 2024-10-19 14:37:33 |
Judging History
answer
//
// Created by Zlin on 2024/10/19.
//
#include "bits/stdc++.h"
using namespace std;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 3e5 + 5;
const ll inf = 1e17;
int n, m, vis[N];
ll dis[N];
struct edge {
int v, val;
bool operator<(const edge &x) const {
if (v != x.v) return v < x.v;
return val < x.val;
}
};
vector<edge> e[N];
void dij(int s) {
priority_queue<pll> q;
int tag, val;
q.push({0, s});
dis[s] = 0;
while (!q.empty()) {
int u = q.top().second;
q.pop();
if (vis[u]) continue;
vis[u] = 1;
sort(e[u].begin(), e[u].end());
tag = -1;
while (!e[u].empty()) {
if (e[u].back().v == tag) e[u].pop_back();
else {
int siz = e[u].size();
if (e[u][siz - 1].v == e[u][siz - 2].v) {
val = e[u][siz - 1].val + e[u][siz - 2].val;
tag = e[u][siz - 1].v;
e[u].pop_back();
e[u].pop_back();
} else {
val = e[u][siz - 1].val;
tag = e[u][siz - 1].v;
e[u].pop_back();
}
if (dis[tag] > dis[u] + val) {
dis[tag] = dis[u] + val;
if (!vis[tag])
q.push({-dis[tag], tag});
}
}
}
}
}
inline void Zlin() {
cin >> n >> m;
for (int i = 1, u, v, val; i <= m; i++) {
cin >> u >> v >> val;
e[u].push_back({v, val});
e[v].push_back({u, val});
}
for (int i = 1; i <= n; i++) vis[i] = 0, dis[i] = inf;
dij(1);
cout << dis[n] << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int ttt = 1;
// cin >> ttt;
while (ttt--) Zlin();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7724kb
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
Runtime Error
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 ...