Submission #789797

#TimeUsernameProblemLanguageResultExecution timeMemory
789797HanksburgerRobot (JOI21_ho_t4)C++17
100 / 100
332 ms64716 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<long long, pair<long long, long long> > > adj[100005]; vector<pair<long long, long long> > vec[300005]; priority_queue<pair<long long, long long> > pq; long long dist[300005], final[300005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, sz; cin >> n >> m; for (long long i=1; i<=m; i++) { long long u, v, c, p; cin >> u >> v >> c >> p; adj[u].push_back({c, {v, p}}); adj[v].push_back({c, {u, p}}); vec[u].push_back({v, p}); vec[v].push_back({u, p}); } sz=n; for (long long i=1; i<=n; i++) { sort(adj[i].begin(), adj[i].end()); long long ind=0; for (long long j=1; j<adj[i].size(); j++) { if (adj[i][ind].first!=adj[i][j].first) { if (j-ind==1) vec[i].push_back({adj[i][ind].second.first, 0}); else { long long sum=0; for (long long k=ind; k<j; k++) sum+=adj[i][k].second.second; sz++; vec[i].push_back({sz, 0}); for (long long k=ind; k<j; k++) { vec[adj[i][k].second.first].push_back({sz, 0}); vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second}); } } ind=j; } } long long j=adj[i].size(); if (j-ind==1) vec[i].push_back({adj[i][ind].second.first, 0}); else { long long sum=0; for (long long k=ind; k<j; k++) sum+=adj[i][k].second.second; sz++; vec[i].push_back({sz, 0}); for (long long k=ind; k<j; k++) { vec[adj[i][k].second.first].push_back({sz, 0}); vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second}); } } } for (long long i=1; i<=sz; i++) dist[i]=1e18; dist[1]=0; pq.push({0, 1}); while (!pq.empty()) { long long u=pq.top().second; pq.pop(); if (final[u]) continue; final[u]=1; for (long long i=0; i<vec[u].size(); i++) { long long v=vec[u][i].first, w=vec[u][i].second; if (dist[u]+w<dist[v]) { dist[v]=dist[u]+w; if (!final[v]) pq.push({-dist[v], v}); } } } if (dist[n]<5e17) cout << dist[n]; else cout << -1; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (long long j=1; j<adj[i].size(); j++)
      |                             ~^~~~~~~~~~~~~~
Main.cpp:78:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (long long i=0; i<vec[u].size(); i++)
      |                             ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...