Submission #529539

#TimeUsernameProblemLanguageResultExecution timeMemory
529539abc864197532Robot (JOI21_ho_t4)C++17
0 / 100
126 ms26220 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define eb emplace_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 100000; struct edge { int v, c, p; }; vector <edge> adj[N]; int main () { owo; int n, m; cin >> n >> m; for (int i = 0, u, v, c, p; i < m; ++i) { cin >> u >> v >> c >> p, --u, --v, --c; adj[u].pb({v, c, p}); adj[v].pb({u, c, p}); } vector <vector <pair <int, lli>>> adj2(n); vector <lli> cost(m, 0); for (int i = 0; i < n; ++i) { for (edge &e : adj[i]) { cost[e.c] += e.p; } for (edge &e : adj[i]) { adj2[i].eb(e.v, min(cost[e.c] - e.p, 1ll * e.p)); } for (edge &e : adj[i]) { cost[e.c] = 0; } } vector <lli> dis(n, 1ll << 60); dis[0] = 0; priority_queue <pair <lli, int>, vector <pair <lli, int>>, greater <pair <lli, int>>> pq; pq.emplace(dis[0], 0); while (!pq.empty()) { lli d; int v; tie(d, v) = pq.top(); pq.pop(); if (d > dis[v]) continue; for (auto [u, w] : adj2[v]) if (dis[u] > dis[v] + w) { dis[u] = dis[v] + w; pq.emplace(dis[u], u); } } if (dis[n - 1] == 1ll << 60) dis[n - 1] = -1; cout << dis[n - 1] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...