Submission #929281

#TimeUsernameProblemLanguageResultExecution timeMemory
929281dubabubaAirplane (NOI23_airplane)C++14
0 / 100
136 ms35932 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair const int mxn = 1e6 + 10; int dis[mxn], a[mxn], n, m; vector<int> adj[mxn]; int main() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } memset(dis, -1, sizeof dis); priority_queue<pii> pq; pq.push(MP(0, 1)); while(pq.size()) { int d = -pq.top().ff; int u = pq.top().ss; pq.pop(); if(dis[u] > -1) continue; dis[u] = d; for(int v : adj[u]) if(dis[v] == -1) pq.push(MP(-(d + max(1, abs(a[v] - a[u]))), v)); } cout << dis[n] << endl; return 0; } /* 6 7 0 100 10 7 8 0 1 3 1 2 2 3 3 4 3 5 2 5 2 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...