Submission #424351

#TimeUsernameProblemLanguageResultExecution timeMemory
424351Harry464Robot (JOI21_ho_t4)C++14
0 / 100
478 ms44608 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(); 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 = u, mv = 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][0]) mini[v][0] = 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][0] || !probao[make_pair(mu,mv)]) mini[v][0] = 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:46: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]
   46 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:54: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]
   54 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:79: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]
   79 |         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...