답안 #970946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970946 2024-04-27T15:17:33 Z CSQ31 Airplane (NOI23_airplane) C++17
100 / 100
276 ms 26976 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
const int MAXN = 2e5+5;
vector<int>adj[MAXN];
ll d0[MAXN],d1[MAXN],a[MAXN];
int main()
{
    owo
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++){
        int v,u;
        cin>>v>>u;
        v--;
        u--;
        adj[v].pb(u);
        adj[u].pb(v);
    }
    for(int i=0;i<n;i++)d0[i] = d1[i] = 1e18;

    d0[0] = 0;
    priority_queue<PII,vector<PII>,greater<PII>>pq;
    pq.push({0,0});
    while(!pq.empty()){
        ll d = pq.top().fi;
        int v = pq.top().se;
        pq.pop();
        if(d != d0[v])continue;
        for(int x:adj[v]){
            if(d+1 <= a[x] && a[x] < d0[x]){
                d0[x] = a[x];
                pq.push({a[x],x});
            }else if(d+1 > a[x] && d+1 < d0[x]){
                d0[x] = d+1;
                pq.push({d+1,x});
            }
        }
    }
    d1[n-1] = 0;
    pq.push({0,n-1});
    while(!pq.empty()){
        ll d = pq.top().fi;
        int v = pq.top().se;
        pq.pop();
        if(d != d1[v])continue;
        for(int x:adj[v]){
            if(d+1 <= a[x] && a[x] < d1[x]){
                d1[x] = a[x];
                pq.push({a[x],x});
            }else if(d+1 > a[x] && d+1 < d1[x]){
                d1[x] = d+1;
                pq.push({d+1,x});
            }
        }
    }
    ll ans = INF;
    for(int i=0;i<n;i++){
        ans = min(ans,2*max(d0[i],d1[i]));
        for(int x:adj[i]){
            ans = min(ans,2*max(d0[i],d1[x])+1);
        }
    }
    cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 57 ms 19084 KB Output is correct
3 Correct 59 ms 19544 KB Output is correct
4 Correct 60 ms 19880 KB Output is correct
5 Correct 64 ms 20256 KB Output is correct
6 Correct 63 ms 20264 KB Output is correct
7 Correct 61 ms 20304 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9564 KB Output is correct
8 Correct 3 ms 9564 KB Output is correct
9 Correct 3 ms 9564 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 3 ms 9564 KB Output is correct
12 Correct 3 ms 9564 KB Output is correct
13 Correct 3 ms 9796 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 9680 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9564 KB Output is correct
8 Correct 3 ms 9564 KB Output is correct
9 Correct 3 ms 9564 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 3 ms 9564 KB Output is correct
12 Correct 3 ms 9564 KB Output is correct
13 Correct 3 ms 9796 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 9680 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9564 KB Output is correct
22 Correct 3 ms 9816 KB Output is correct
23 Correct 3 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 4 ms 9564 KB Output is correct
26 Correct 3 ms 9680 KB Output is correct
27 Correct 4 ms 9816 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
29 Correct 3 ms 9820 KB Output is correct
30 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 57 ms 19084 KB Output is correct
3 Correct 59 ms 19544 KB Output is correct
4 Correct 60 ms 19880 KB Output is correct
5 Correct 64 ms 20256 KB Output is correct
6 Correct 63 ms 20264 KB Output is correct
7 Correct 61 ms 20304 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 3 ms 9564 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 3 ms 9564 KB Output is correct
20 Correct 3 ms 9564 KB Output is correct
21 Correct 3 ms 9796 KB Output is correct
22 Correct 3 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 3 ms 9680 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
29 Correct 3 ms 9564 KB Output is correct
30 Correct 3 ms 9816 KB Output is correct
31 Correct 3 ms 9564 KB Output is correct
32 Correct 3 ms 9564 KB Output is correct
33 Correct 4 ms 9564 KB Output is correct
34 Correct 3 ms 9680 KB Output is correct
35 Correct 4 ms 9816 KB Output is correct
36 Correct 3 ms 9820 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 3 ms 9820 KB Output is correct
39 Correct 152 ms 20568 KB Output is correct
40 Correct 101 ms 19380 KB Output is correct
41 Correct 98 ms 19536 KB Output is correct
42 Correct 92 ms 19404 KB Output is correct
43 Correct 98 ms 19840 KB Output is correct
44 Correct 85 ms 19400 KB Output is correct
45 Correct 90 ms 19496 KB Output is correct
46 Correct 88 ms 19536 KB Output is correct
47 Correct 90 ms 19540 KB Output is correct
48 Correct 88 ms 19536 KB Output is correct
49 Correct 119 ms 20328 KB Output is correct
50 Correct 113 ms 20048 KB Output is correct
51 Correct 104 ms 20236 KB Output is correct
52 Correct 169 ms 23240 KB Output is correct
53 Correct 162 ms 22220 KB Output is correct
54 Correct 185 ms 22180 KB Output is correct
55 Correct 229 ms 22476 KB Output is correct
56 Correct 259 ms 25960 KB Output is correct
57 Correct 229 ms 26052 KB Output is correct
58 Correct 235 ms 26952 KB Output is correct
59 Correct 246 ms 26976 KB Output is correct
60 Correct 276 ms 26824 KB Output is correct
61 Correct 221 ms 26568 KB Output is correct
62 Correct 233 ms 25780 KB Output is correct
63 Correct 247 ms 25956 KB Output is correct
64 Correct 195 ms 25796 KB Output is correct
65 Correct 221 ms 25904 KB Output is correct
66 Correct 274 ms 25920 KB Output is correct
67 Correct 254 ms 26236 KB Output is correct