Submission #850480

#TimeUsernameProblemLanguageResultExecution timeMemory
850480hqminhuwuRobot (JOI21_ho_t4)C++17
100 / 100
1016 ms110064 KiB
#include <bits/stdc++.h> #define forr(_a,_b,_c) for(_a = _b; _a <= _c; ++_a) #define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> _c;) #define forf(_a,_b,_c) for(_a = _b; _a < _c; ++_a) #define st first #define nd second #define ll long long #define ull unsigned long long #define pii pair <ll,ll> #define pll pair <ll,ll> #define piii pair <ll,pii> #define vi vector <int> #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define file "test" #define ns nd.st #define nn nd.nd using namespace std; const int N = 2e5 + 5; const ll oo = 1e18; const ll mod = 1e9 + 7; map <int,vector<piii>> a[N]; map <int,ll> dp[N],sum[N]; priority_queue <piii,vector<piii>,greater<piii>> q; void calc(){ q.push({0,{-1,0}}); while (!q.empty()){ piii u= q.top(); q.pop(); u.ns = - u.ns; u.nn = -u.nn; if (u.st != dp[u.ns][u.nn]) continue; //cout << u.st << " " << u.ns << " " << u.nn << "\n"; if (!u.nn){ for (auto &f : a[u.ns]) for (piii v : f.nd){ ll cost = u.st + sum[u.ns][v.ns] - v.nn; if (dp[v.st][0] > cost) dp[v.st][0] = cost, q.push({dp[v.st][0],{-v.st,0}}); //cout << cost << " "; cost = u.st + v.nn; //cout << cost << " "; if (dp[v.st][0] > cost) dp[v.st][0] = cost, q.push({dp[v.st][0],{-v.st,0}}); cost = u.st; //cout << cost << "\n"; if (!dp[v.st][v.ns] || dp[v.st][v.ns] > cost) dp[v.st][v.ns] = cost, q.push({dp[v.st][v.ns],{-v.st,-v.ns}}); } } else { for (piii v : a[u.ns][u.nn]){ ll cost = u.st + sum[u.ns][u.nn] - v.nn; //cout << cost << "\n"; if (dp[v.st][0] > cost) dp[v.st][0] = cost, q.push({cost,{-v.st,0}}); } } } } int n,m,i,u,v,w,t; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; forr (i,1,m){ cin >> u >> v >> w >> t; a[u][w].pb({v,{w,t}}); a[v][w].pb({u,{w,t}}); sum[v][w] += t; sum[u][w] += t; } forr (i,2,n) dp[i][0] = oo; calc(); if (dp[n][0] == oo) cout << "-1"; else cout << dp[n][0]; return 0; } /* */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:83:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   83 |     else
      |     ^~~~
Main.cpp:85:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   85 |  return 0;
      |  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...