Submission #1292396

#TimeUsernameProblemLanguageResultExecution timeMemory
1292396dungntRobot (JOI21_ho_t4)C++20
100 / 100
130 ms15480 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<ll, int> using namespace std; const int N = 100000 + 5; const int M = 200000 + 5; const ll INF = 1e18; struct E { int v, c, w; E(){} E(int _v, int _c, int _w) { v = _v; c = _c; w = _w; } }; int n, m; vector<E> adj[N]; ll d[N], sum[M], best[M]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "baitap" if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } cin >> n >> m; for(int i = 1; i <= m; i++) { int u, v, c, w; cin >> u >> v >> c >> w; adj[u].push_back({v, c, w}); adj[v].push_back({u, c, w}); } for(int i = 1; i <= n; i++) d[i] = INF; for(int i = 1; i <= m; i++) best[i] = INF; priority_queue<pii, vector<pii>, greater<pii>> pq; d[1] = 0; pq.push({0, 1}); while(!pq.empty()) { auto [du, u] = pq.top(); pq.pop(); if(du != d[u]) continue; for(auto [v, c, w] : adj[u]) { sum[c] += w; if(best[c] > d[v]) best[c] = d[v]; } for(auto [v, c, w] : adj[u]) { ll t1 = w < sum[c] - w ? w : sum[c] - w; ll nd1 = du + t1; if(d[v] > nd1) { d[v] = nd1; pq.push({nd1, v}); } ll nd2 = best[c] + sum[c] - w; if(d[v] > nd2) { d[v] = nd2; pq.push({nd2, v}); } } for(auto [v, c, w] : adj[u]) { sum[c] = 0; best[c] = INF; } } if(d[n] == INF) cout << -1; else cout << d[n]; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...