Submission #424346

#TimeUsernameProblemLanguageResultExecution timeMemory
424346Harry464Robot (JOI21_ho_t4)C++14
0 / 100
833 ms61856 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <map> using namespace std; typedef long long ll; vector <vector<pair <ll, pair<ll,ll> > > > adjl(1000000); map <pair<ll,ll>, bool> probao; int main() { ll n, m; cin >> n >> m; for (int i = 0; i < m; i++){ ll u, v, c, p; cin >> u >> v >> c >> p; pair <ll,ll> drugi = make_pair(c,p); u--, v--; adjl[u].push_back(make_pair(v, drugi)), adjl[v].push_back(make_pair(u, drugi)); } vector <ll> tmp(2,1000000000000000000); vector <ll> cols(m + 1, 0); vector <vector <ll> > mini(n, tmp); mini[0][0] = 0, mini[0][1] = 0; priority_queue <pair <ll, pair<ll,pair<ll,ll> > > > dijk; dijk.push(make_pair(0, make_pair(0, make_pair(-1,-1)))); while (dijk.size()){ ll pric = -dijk.top().first, u = dijk.top().second.first, ori = dijk.top().second.second.first, col = dijk.top().second.second.first; dijk.pop(); if (col != 0 && pric > mini[u][0]) continue; for (int i = 0; i < adjl[u].size(); i++){ ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second; if (v != ori || col != 0) cols[c] += p; } for (int i = 0; i < adjl[u].size(); i++){ ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second; ll mu = min(u,v), mv = max(u,v); if (cols[c] - p == 0 && mini[v][0] > pric) mini[v][0] = pric, dijk.push(make_pair(-pric, make_pair(v, make_pair(u,c)))); if (cols[c] - p > 0){ ll most = cols[c] - p; if (most + pric < mini[v][0]) mini[v][0] = pric + most, dijk.push(make_pair(-pric-most, make_pair(v, make_pair(u,c)))); if (p + pric < mini[v][1]) mini[v][1] = pric + p, probao[make_pair(mu,mv)] = true, dijk.push(make_pair(-pric-p, make_pair(v, make_pair(u,0)))); } if (p + pric < mini[v][1] || !probao[make_pair(mu,mv)]) mini[v][1] = min(mini[v][1], pric + p), probao[make_pair(mu,mv)] = true, dijk.push(make_pair(-pric-p, make_pair(v, make_pair(u,0)))); } for (int i = 0; i < adjl[u].size(); i++){ ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second; if (v != ori || col != 0) cols[c] -= p; } } if (min(mini[n-1][0], mini[n-1][1]) == 1000000000000000000) cout << "-1"; else cout << min(mini[n-1][0], mini[n-1][1]); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:49:27: warning: comparison of integer expressions of different signedness: '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]
   49 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:57:27: warning: comparison of integer expressions of different signedness: '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]
   57 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:82:27: warning: comparison of integer expressions of different signedness: '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]
   82 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...