답안 #1102766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102766 2024-10-18T19:34:36 Z ttamx Airplane (NOI23_airplane) C++17
0 / 100
55 ms 16380 KB
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;

const int N=2e5+5;
const int INF=INT_MAX/2;

int n,m;
int a[N];
vector<int> adj[N];
int dist1[N],dist2[N];
int ans=INF;

void dijkstra(int st,int *dist){
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    for(int i=1;i<=n;i++)dist[i]=INF;
    dist[st]=0;
    pq.emplace(0,st);
    while(!pq.empty()){
        auto [d,u]=pq.top();
        pq.pop();
        if(d>dist[u])continue;
        for(auto v:adj[u]){
            int nd=max(d+1,a[v]);
            if(nd<dist[v]){
                dist[v]=nd;
                pq.emplace(nd,v);
            }
        }
    }
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    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].emplace_back(v);
        adj[v].emplace_back(u);
    }
    dijkstra(1,dist1);
    dijkstra(n,dist2);
    for(int i=1;i<=n;i++){
        int mx=max(dist1[i],dist2[i]);
        ans=min(ans,mx*2-(mx>a[i]));
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Incorrect 55 ms 16380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 2 ms 6648 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Incorrect 2 ms 6712 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 2 ms 6648 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Incorrect 2 ms 6712 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Incorrect 55 ms 16380 KB Output isn't correct
3 Halted 0 ms 0 KB -