Submission #956682

#TimeUsernameProblemLanguageResultExecution timeMemory
956682peterandvoiRobot (JOI21_ho_t4)C++17
0 / 100
163 ms35032 KiB
#include <bits/stdc++.h> using namespace std; #ifdef ngu #include "debug.h" #else #define debug(...) 42 #endif const int N = (int) 5e5 + 5; int n, m; long long s[N], d[N]; vector<pair<int, long long>> g[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef ngu freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); #endif cin >> n >> m; map<pair<int, int>, int> id; vector<tuple<int, int, int, int>> edges; int idx = n; auto add = [&](int u, int c, int v) { if (!id.count({u, c})) { id[{u, c}] = ++idx; } s[id[{u, c}]] += v; }; for (int i = 1; i <= m; ++i) { int u, v, c, p; cin >> u >> v >> c >> p; edges.emplace_back(u, v, c, p); add(u, c, p); add(v, c, p); } for (auto [u, v, c, p] : edges) { int x = id[{u, c}], y = id[{v, c}]; long long a = s[x], b = s[y]; g[u].emplace_back(v, min(1LL * p, a - p)); g[v].emplace_back(u, min(1LL * p, b - p)); g[u].emplace_back(y, 0); g[v].emplace_back(x, 0); g[x].emplace_back(v, a - p); g[y].emplace_back(u, b - p); } memset(d, 0x3f, sizeof(d)); using T = pair<long long, int>; priority_queue<T, vector<T>, greater<T>> pq; d[1] = 0; pq.emplace(0, 1); while (pq.size()) { auto [c, u] = pq.top(); pq.pop(); if (c == d[u]) { for (auto [v, w] : g[u]) { if (d[v] > d[u] + w) { pq.emplace(v, d[v] = d[u] + w); } } } } const long long INF = (long long) 1e18; cout << (d[n] > INF ? -1 : d[n]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...