Submission #893367

# Submission time Handle Problem Language Result Execution time Memory
893367 2023-12-27T03:31:10 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
294 ms 35144 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=4e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll d[3][maxn];
ll n;
vector<ll>g[maxn];
ll a[maxn];
void dij(ll t,ll s)
{
    for(int i=1;i<=n;i++) d[t][i]=inf;
    d[t][s]=0;
    priority_queue<pli,vector<pli>,greater<pli>>pq;
    pq.push({d[t][s],s});
    while(!pq.empty())
    {
        ll u=pq.top().se;
        pq.pop();
        for(int v:g[u])
        {
            if(d[t][v]>max(d[t][u]+1,a[v]))
            {
                d[t][v]=max(d[t][u]+1,a[v]);
                pq.push({d[t][v],v});
            }
        }
    }
}
ll m;
ll ans=inf;
void solve()
{
    cin >> n >> m ;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for(int i=1;i<=m;i++)
    {
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dij(0,1);
    dij(1,n);
    for(int i=1;i<=n;i++)
    {
        if(abs(d[0][i]-d[1][i])<=1) ans=min(ans,d[0][i]+d[1][i]);
    }
    cout << ans;
}
int main()
{
    fastio
    //freopen("c.INP","r",stdin);
    //freopen("c.OUT","w",stdout);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 55 ms 25156 KB Output is correct
3 Correct 56 ms 25132 KB Output is correct
4 Correct 75 ms 25272 KB Output is correct
5 Correct 71 ms 25240 KB Output is correct
6 Correct 59 ms 25168 KB Output is correct
7 Correct 59 ms 25168 KB Output is correct
8 Correct 3 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14820 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 4 ms 14684 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 4 ms 14684 KB Output is correct
12 Correct 4 ms 14780 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14732 KB Output is correct
15 Correct 4 ms 15004 KB Output is correct
16 Correct 4 ms 14776 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14820 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 4 ms 14684 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 4 ms 14684 KB Output is correct
12 Correct 4 ms 14780 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14732 KB Output is correct
15 Correct 4 ms 15004 KB Output is correct
16 Correct 4 ms 14776 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 4 ms 14684 KB Output is correct
20 Correct 4 ms 14684 KB Output is correct
21 Correct 5 ms 14836 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 5 ms 14684 KB Output is correct
24 Correct 4 ms 14684 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 4 ms 14940 KB Output is correct
27 Correct 4 ms 14940 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 5 ms 14936 KB Output is correct
30 Correct 4 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 55 ms 25156 KB Output is correct
3 Correct 56 ms 25132 KB Output is correct
4 Correct 75 ms 25272 KB Output is correct
5 Correct 71 ms 25240 KB Output is correct
6 Correct 59 ms 25168 KB Output is correct
7 Correct 59 ms 25168 KB Output is correct
8 Correct 3 ms 14680 KB Output is correct
9 Correct 3 ms 14820 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 4 ms 14684 KB Output is correct
15 Correct 4 ms 14684 KB Output is correct
16 Correct 4 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 4 ms 14684 KB Output is correct
19 Correct 4 ms 14684 KB Output is correct
20 Correct 4 ms 14780 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 4 ms 14732 KB Output is correct
23 Correct 4 ms 15004 KB Output is correct
24 Correct 4 ms 14776 KB Output is correct
25 Correct 4 ms 14936 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 4 ms 14684 KB Output is correct
28 Correct 4 ms 14684 KB Output is correct
29 Correct 5 ms 14836 KB Output is correct
30 Correct 4 ms 14940 KB Output is correct
31 Correct 5 ms 14684 KB Output is correct
32 Correct 4 ms 14684 KB Output is correct
33 Correct 4 ms 14940 KB Output is correct
34 Correct 4 ms 14940 KB Output is correct
35 Correct 4 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 5 ms 14936 KB Output is correct
38 Correct 4 ms 14936 KB Output is correct
39 Correct 142 ms 26196 KB Output is correct
40 Correct 155 ms 26196 KB Output is correct
41 Correct 140 ms 26596 KB Output is correct
42 Correct 127 ms 26328 KB Output is correct
43 Correct 106 ms 26360 KB Output is correct
44 Correct 89 ms 26376 KB Output is correct
45 Correct 94 ms 26340 KB Output is correct
46 Correct 98 ms 26192 KB Output is correct
47 Correct 94 ms 26196 KB Output is correct
48 Correct 96 ms 26196 KB Output is correct
49 Correct 127 ms 26192 KB Output is correct
50 Correct 140 ms 26668 KB Output is correct
51 Correct 129 ms 26348 KB Output is correct
52 Correct 208 ms 31020 KB Output is correct
53 Correct 178 ms 30844 KB Output is correct
54 Correct 177 ms 31004 KB Output is correct
55 Correct 211 ms 31008 KB Output is correct
56 Correct 241 ms 34740 KB Output is correct
57 Correct 294 ms 34860 KB Output is correct
58 Correct 250 ms 34732 KB Output is correct
59 Correct 290 ms 35144 KB Output is correct
60 Correct 233 ms 34924 KB Output is correct
61 Correct 269 ms 34804 KB Output is correct
62 Correct 222 ms 34772 KB Output is correct
63 Correct 219 ms 34792 KB Output is correct
64 Correct 229 ms 35092 KB Output is correct
65 Correct 226 ms 34820 KB Output is correct
66 Correct 240 ms 34752 KB Output is correct
67 Correct 279 ms 35092 KB Output is correct