답안 #1102769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102769 2024-10-18T19:45:20 Z ttamx Airplane (NOI23_airplane) C++17
100 / 100
218 ms 17564 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++){
        ans=min(ans,max(dist1[i],dist2[i])*2);
    }
    for(int u=1;u<=n;u++){
        for(auto v:adj[u]){
            ans=min(ans,max(dist1[u],dist2[v])*2+1);
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 51 ms 13584 KB Output is correct
3 Correct 61 ms 13580 KB Output is correct
4 Correct 55 ms 13644 KB Output is correct
5 Correct 55 ms 13580 KB Output is correct
6 Correct 55 ms 13640 KB Output is correct
7 Correct 63 ms 13644 KB Output is correct
8 Correct 2 ms 6652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6652 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6592 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6588 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6584 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6652 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6592 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6588 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6584 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 2 ms 6692 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 3 ms 6648 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 3 ms 6480 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 3 ms 6908 KB Output is correct
30 Correct 3 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 51 ms 13584 KB Output is correct
3 Correct 61 ms 13580 KB Output is correct
4 Correct 55 ms 13644 KB Output is correct
5 Correct 55 ms 13580 KB Output is correct
6 Correct 55 ms 13640 KB Output is correct
7 Correct 63 ms 13644 KB Output is correct
8 Correct 2 ms 6652 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6652 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6592 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 3 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 3 ms 6588 KB Output is correct
23 Correct 3 ms 6736 KB Output is correct
24 Correct 3 ms 6480 KB Output is correct
25 Correct 3 ms 6584 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 3 ms 6480 KB Output is correct
28 Correct 2 ms 6692 KB Output is correct
29 Correct 2 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
31 Correct 3 ms 6648 KB Output is correct
32 Correct 2 ms 6480 KB Output is correct
33 Correct 3 ms 6480 KB Output is correct
34 Correct 3 ms 6480 KB Output is correct
35 Correct 3 ms 6480 KB Output is correct
36 Correct 3 ms 6736 KB Output is correct
37 Correct 3 ms 6908 KB Output is correct
38 Correct 3 ms 6736 KB Output is correct
39 Correct 111 ms 13636 KB Output is correct
40 Correct 81 ms 13648 KB Output is correct
41 Correct 87 ms 13640 KB Output is correct
42 Correct 90 ms 13592 KB Output is correct
43 Correct 78 ms 13640 KB Output is correct
44 Correct 73 ms 13640 KB Output is correct
45 Correct 82 ms 13676 KB Output is correct
46 Correct 79 ms 13640 KB Output is correct
47 Correct 76 ms 13780 KB Output is correct
48 Correct 83 ms 13640 KB Output is correct
49 Correct 113 ms 13660 KB Output is correct
50 Correct 93 ms 13640 KB Output is correct
51 Correct 89 ms 13640 KB Output is correct
52 Correct 154 ms 15348 KB Output is correct
53 Correct 145 ms 15352 KB Output is correct
54 Correct 177 ms 15328 KB Output is correct
55 Correct 148 ms 15348 KB Output is correct
56 Correct 181 ms 17472 KB Output is correct
57 Correct 190 ms 17464 KB Output is correct
58 Correct 177 ms 17468 KB Output is correct
59 Correct 208 ms 17564 KB Output is correct
60 Correct 179 ms 17512 KB Output is correct
61 Correct 218 ms 17468 KB Output is correct
62 Correct 172 ms 17328 KB Output is correct
63 Correct 154 ms 17492 KB Output is correct
64 Correct 162 ms 17484 KB Output is correct
65 Correct 170 ms 17484 KB Output is correct
66 Correct 172 ms 17444 KB Output is correct
67 Correct 182 ms 17464 KB Output is correct