Submission #1112910

#TimeUsernameProblemLanguageResultExecution timeMemory
1112910AvianshAirplane (NOI23_airplane)C++17
0 / 100
1103 ms48248 KiB
#include <bits/stdc++.h> using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; int a[n]; for(int &i : a){ cin >> i; } vector<int>g[n]; for(int i = 0;i<m;i++){ int a,b; cin >> a >> b; a--;b--; g[a].push_back(b); g[b].push_back(a); } set<int>vis1; map<array<int,2>,int>dist; set<array<int,3>>pq; pq.insert({0,0,0}); long long ans = 0; while(!pq.empty()){ array<int,3>cur = *(pq.begin()); //cout <<cur[0] << " " << cur[1] << " " << cur[2] << "\n"; pq.erase(pq.begin()); if(cur[1]==0&&cur[2]==n-1){ ans=cur[0]; break; } int cura = cur[1]; dist[{cur[1],cur[2]}]=cur[0]; if(cura>a[cur[2]]){ if(cur[0]+cura-a[cur[2]]<dist[{a[cur[2]],cur[2]}]||dist[{a[cur[2]],cur[2]}]==0){ pq.erase({dist[{a[cur[2]],cur[2]}],a[cur[2]],cur[2]}); dist[{a[cur[2]],cur[2]}]=cur[0]+cura-a[cur[2]]; pq.insert({cur[0]+cura-a[cur[2]],a[cur[2]],cur[2]}); } } for(int i : g[cur[2]]){ if(cura+1>=a[i]){ if(cur[0]+1<dist[{cura+1,i}]||dist[{cura+1,i}]==0){ pq.erase({dist[{cura+1,i}],cura+1,i}); dist[{cura+1,i}]=cur[0]+1; pq.insert({cur[0]+1,cura+1,i}); } } else{ if(a[i]-cura+cur[0]<dist[{a[i],i}]||dist[{a[i],i}]==0){ pq.erase({dist[{a[i],i}],a[i],i}); dist[{a[i],i}]=a[i]-cura+cur[0]; pq.insert({a[i]-cura+cur[0],a[i],i}); } } if(cura-1>=a[i]){ if(cur[0]+1<dist[{cura-1,i}]||dist[{cura-1,i}]==0){ pq.erase({dist[{cura-1,i}],cura-1,i}); dist[{cura-1,i}]=cur[0]+1; pq.insert({cur[0]+1,cura-1,i}); } } if(cura>=a[i]){ if(cur[0]+1<dist[{cura,i}]||dist[{cura,i}]==0){ pq.erase({dist[{cura,i}],cura,i}); dist[{cura,i}]=cur[0]+1; pq.insert({cur[0]+1,cura,i}); } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...