Submission #1137752

#TimeUsernameProblemLanguageResultExecution timeMemory
1137752varun312Olympic Bus (JOI20_ho_t4)C++20
5 / 100
1095 ms3400 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define fi first #define se second #define endl "\n" #define inf ((ll)2e17) #define len ((ll)205) struct edge { ll a,b,c,d; }; using pii = pair<ll, ll>; ll dist[len]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(0); ll n,m; cin >> n >> m; vector<edge> v(m+1); vector<vector<pii>> g(n+1); for (ll i = 1; i <= m; i++) { cin >> v[i].a >> v[i].b >> v[i].c >> v[i].d; g[v[i].a].pb({v[i].b, v[i].c}); } ll ans = inf; for (ll i = 0; i <= m; i++) { for (ll j = 0; j < g[v[i].a].size(); j++) { if (g[v[i].a][j].fi == v[i].b && g[v[i].a][j].se == v[i].c) { g[v[i].a].erase(g[v[i].a].begin() + j); g[v[i].b].pb({v[i].a, v[i].c}); break; } } // vector<ll> dist(n+1, inf); memset(dist, 0x3f3f3f3f3f3f3f3f, (n+1) * sizeof(ll)); dist[0] = dist[1] = 0; priority_queue<pii, vector<pii>, greater<pii>> pq; pq.push({0, 1}); while (!pq.empty()) { auto e = pq.top(); pq.pop(); if (dist[e.se] != e.fi) { continue; } for (auto nod : g[e.se]) { if (dist[nod.fi] > e.fi + nod.se) { dist[nod.fi] = e.fi + nod.se; pq.push({dist[nod.fi], nod.fi}); } } } ll tmp = dist[n]; // for (auto e : dist) { // cout << e << " "; // } // cout << endl; // dist.assign(n+1, inf); memset(dist, 0x3f3f3f3f3f3f3f3f, (n+1) * sizeof(ll)); dist[0] = dist[n] = 0; pq.push({0, n}); while (!pq.empty()) { auto e = pq.top(); pq.pop(); if (dist[e.se] != e.fi) { continue; } for (auto nod : g[e.se]) { if (dist[nod.fi] > e.fi + nod.se) { dist[nod.fi] = e.fi + nod.se; pq.push({dist[nod.fi], nod.fi}); } } } // for (auto e : dist) { // cout << e << " "; // } // cout << endl << endl; for (ll j = 0; j < g[v[i].b].size(); j++) { if (g[v[i].b][j].fi == v[i].a && g[v[i].b][j].se == v[i].c) { g[v[i].b].erase(g[v[i].b].begin() + j); g[v[i].a].pb({v[i].b, v[i].c}); break; } } ans = min(ans, tmp + dist[1] + v[i].d); } cout << (ans == inf ? -1 : ans) << endl; }

Compilation message (stderr)

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:51:22: warning: overflow in conversion from 'long int' to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
   51 |         memset(dist, 0x3f3f3f3f3f3f3f3f, (n+1) * sizeof(ll));
      |                      ^~~~~~~~~~~~~~~~~~
ho_t4.cpp:77:22: warning: overflow in conversion from 'long int' to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
   77 |         memset(dist, 0x3f3f3f3f3f3f3f3f, (n+1) * sizeof(ll));
      |                      ^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...