Submission #224110

#TimeUsernameProblemLanguageResultExecution timeMemory
224110dwscOlympic Bus (JOI20_ho_t4)C++14
5 / 100
138 ms428 KiB
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> ii; typedef pair<ii,int> i3; main(){ int n,m; cin >> n >> m; if (m <= 1000){ int ans = 1e18; i3 edges[m]; int invert[m+1]; for (int i = 0; i < m; i++) { cin >> edges[i].first.first >> edges[i].first.second >> edges[i].second; cin >> invert[i]; } invert[m] = 0; for (int i = 0; i < m+1; i++){ int temp = invert[i]; vector<ii> tempadj[n+1]; for (int j = 0; j < m; j++){ if (j == i) tempadj[edges[j].first.second].push_back(ii(edges[j].first.first,edges[j].second)); else tempadj[edges[j].first.first].push_back(ii(edges[j].first.second,edges[j].second)); } int dist1[n+1],dist2[n+1]; for (int j = 1; j <= n; j++) dist1[j] = dist2[j] = 1e18; priority_queue<ii,vector<ii>,greater<ii> >pq; pq.push(ii(0,1)); dist1[1] = 0; while (!pq.empty()){ ii f = pq.top(); pq.pop(); int d = f.first, u = f.second; if (d > dist1[u]) continue; for (int j = 0; j < tempadj[u].size(); j++){ ii v = tempadj[u][j]; if (dist1[u]+v.second < dist1[v.first]){ dist1[v.first] = dist1[u]+v.second; pq.push(ii(dist1[v.first],v.first)); } } } pq.push(ii(0,n)); dist2[n] = 0; while (!pq.empty()){ ii f = pq.top(); pq.pop(); int d = f.first, u = f.second; if (d > dist2[u]) continue; for (int j = 0; j < tempadj[u].size(); j++){ ii v = tempadj[u][j]; if (dist2[u]+v.second < dist2[v.first]){ dist2[v.first] = dist2[u]+v.second; pq.push(ii(dist2[v.first],v.first)); } } } ans = min(ans,temp+dist1[n]+dist2[1]); } if (ans == 1e18) cout << -1; else cout << ans; } }

Compilation message (stderr)

ho_t4.cpp:6:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:35:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j = 0; j < tempadj[u].size(); j++){
                                 ~~^~~~~~~~~~~~~~~~~~~
ho_t4.cpp:50:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j = 0; j < tempadj[u].size(); j++){
                                 ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...