답안 #886053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886053 2023-12-11T12:24:53 Z vjudge1 Airplane (NOI23_airplane) C++17
0 / 100
68 ms 59220 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], r[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;
    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;
    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;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  solve();
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 47704 KB Output is correct
2 Incorrect 68 ms 59220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 11 ms 47796 KB Output is correct
3 Correct 12 ms 47708 KB Output is correct
4 Correct 10 ms 47704 KB Output is correct
5 Correct 11 ms 47840 KB Output is correct
6 Incorrect 14 ms 47708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 11 ms 47796 KB Output is correct
3 Correct 12 ms 47708 KB Output is correct
4 Correct 10 ms 47704 KB Output is correct
5 Correct 11 ms 47840 KB Output is correct
6 Incorrect 14 ms 47708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 47704 KB Output is correct
2 Incorrect 68 ms 59220 KB Output isn't correct
3 Halted 0 ms 0 KB -