Submission #886076

# Submission time Handle Problem Language Result Execution time Memory
886076 2023-12-11T12:41:03 Z vjudge1 Airplane (NOI23_airplane) C++17
0 / 100
62 ms 34644 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define MOD 1000000007
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;


int n, m, a[N];
vector<int> g[N];
void solve(){
  cin >> n >> m;
  for(int i = 1; i <= n; ++i) cin >> a[i];
  for(int i = 1; i <= m; ++i){
    int u, v; cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  vector<int> d1(n+1, MOD);
  vector<int> dn(n+1, MOD);
  vector<int> m1(n+1, 0);
  vector<int> mn(n+1, 0);
  priority_queue<pair<int, int>> q;
  q.push({0, 1});
  d1[1] = 0;
  m1[1] = 0;
  vector<bool> vis(n+1);
  while(!q.empty()){
    int v = q.top().second;
    q.pop();
    if(vis[v]) continue;
    vis[v] = 1;
    for(int u: g[v]){
      int w = max(1, a[u] - a[v]);
      if(d1[v] + w < d1[u]){
        m1[u] = max(a[u], m1[v]);
        d1[u] = d1[v] + w;
        q.push({-d1[u], u});
      }
    }
  }
  q.push({0, n});
  fill(all(vis), 0);
  dn[n] = 0;
  mn[n] = 0;
  while(!q.empty()){
    int v = q.top().second;
    q.pop();
    if(vis[v]) continue;
    vis[v] = 1;
    for(int u: g[v]){
      int w = max(1, a[u] - a[v]);
      if(dn[v] + w < dn[u]){
        mn[u] = max(a[u], mn[v]);
        dn[u] = dn[v] + w;
        q.push({-dn[u], u});  
      }
    }
  }
  int ans = MOD;
  for(int i = 1; i <= n; ++i) if(m1[i] == a[i] && mn[i] == a[i]) ans = min(ans, d1[i] + dn[i]);
  cout << ans;
  // vector<int> dp(n+1, 0);
  // dp[1] = 0;
  // for(int i = 2; i <= n; ++i){
  //   dp[i] = dp[i - 1] + max(1, a[i] - a[i - 1]);
  // }
  // vector<int> dp2(n+1, 0);
  // dp2[n] = 0;
  // for(int i = n-1; i >= 1; --i){
  //   dp2[i] = dp2[i + 1] + max(1, a[i] - a[i+1]);
  // }
  // int ans = MOD;
  // int mx = *max_element(a+1,a+1+n);   
  // for(int i = 1; i <= n; ++i){
  //   if(a[i] == mx) ans = min(ans, dp[i] + dp2[i]);
  // }
  // cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  solve();
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB Output is correct
2 Incorrect 62 ms 34644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 6 ms 25204 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Incorrect 6 ms 25276 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 6 ms 25204 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Incorrect 6 ms 25276 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB Output is correct
2 Incorrect 62 ms 34644 KB Output isn't correct
3 Halted 0 ms 0 KB -