답안 #940035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940035 2024-03-07T04:25:45 Z browntoad Airplane (NOI23_airplane) C++14
100 / 100
376 ms 40028 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for(int i = (n); i >= 1; i--)
#define pii pair<int, int>
#define ppp pair<pii, pii>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)


const ll maxn = 2e5+5;
const ll maxm = 1e4+5;
const ll mod = 1e9+7;
const ll inf = 1ll<<60;

vector<int> g[maxn];
vector<int> h(maxn);

int n, m;

int dis[maxn][2];

vector<bool> occ(maxn);
void dij(int st, bool typ){
    // source st, typ = 0: it is n
    fill(ALL(occ), 0);
    REP1(i, n) dis[i][typ] = inf;
    priority_queue<pii, vector<pii>, greater<pii> > pq;

    dis[st][typ] = 0;
    pq.push({0, st});
    while(SZ(pq)){
        pii tp = pq.top(); pq.pop();
        int u = tp.s;
        if (occ[u]) continue;
        occ[u] = 1;
        for(auto v:g[u]){
            if (dis[v][typ] > max(h[v], dis[u][typ]+1)){
                dis[v][typ] = max(h[v], dis[u][typ]+1);
                pq.push({dis[v][typ], v});
            }
        }
    }
}
signed main(){
    IOS();
    cin>>n>>m;
    REP1(i, n) cin>>h[i];
    vector<pii> ee;
    REP(i, m){
        int u, v; cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
        ee.pb({u, v});
    }

    dij(1, 0); dij(n, 1);
    int ans = inf;
    REP1(i, n){
        ans = min(ans, max(dis[i][0], dis[i][1])*2);
    }
    for (auto e:ee){
        int u = e.f, v = e.s;
        ans = min({ans, max(dis[u][0], dis[v][1])*2+1, max(dis[v][0], dis[u][1])*2+1});
    }
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 63 ms 22288 KB Output is correct
3 Correct 63 ms 22720 KB Output is correct
4 Correct 63 ms 23484 KB Output is correct
5 Correct 64 ms 24124 KB Output is correct
6 Correct 65 ms 23624 KB Output is correct
7 Correct 67 ms 23492 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7528 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7512 KB Output is correct
4 Correct 3 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7768 KB Output is correct
7 Correct 3 ms 7772 KB Output is correct
8 Correct 3 ms 7772 KB Output is correct
9 Correct 3 ms 7772 KB Output is correct
10 Correct 3 ms 7772 KB Output is correct
11 Correct 4 ms 7768 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 3 ms 7772 KB Output is correct
14 Correct 4 ms 7772 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 4 ms 7964 KB Output is correct
17 Correct 4 ms 7772 KB Output is correct
18 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7528 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7512 KB Output is correct
4 Correct 3 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7768 KB Output is correct
7 Correct 3 ms 7772 KB Output is correct
8 Correct 3 ms 7772 KB Output is correct
9 Correct 3 ms 7772 KB Output is correct
10 Correct 3 ms 7772 KB Output is correct
11 Correct 4 ms 7768 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 3 ms 7772 KB Output is correct
14 Correct 4 ms 7772 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 4 ms 7964 KB Output is correct
17 Correct 4 ms 7772 KB Output is correct
18 Correct 3 ms 7516 KB Output is correct
19 Correct 4 ms 7768 KB Output is correct
20 Correct 3 ms 7772 KB Output is correct
21 Correct 4 ms 7772 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
23 Correct 4 ms 7772 KB Output is correct
24 Correct 4 ms 7776 KB Output is correct
25 Correct 4 ms 7768 KB Output is correct
26 Correct 4 ms 7768 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7772 KB Output is correct
29 Correct 3 ms 7772 KB Output is correct
30 Correct 4 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 63 ms 22288 KB Output is correct
3 Correct 63 ms 22720 KB Output is correct
4 Correct 63 ms 23484 KB Output is correct
5 Correct 64 ms 24124 KB Output is correct
6 Correct 65 ms 23624 KB Output is correct
7 Correct 67 ms 23492 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7528 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7512 KB Output is correct
14 Correct 3 ms 7768 KB Output is correct
15 Correct 3 ms 7772 KB Output is correct
16 Correct 3 ms 7772 KB Output is correct
17 Correct 3 ms 7772 KB Output is correct
18 Correct 3 ms 7772 KB Output is correct
19 Correct 4 ms 7768 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 3 ms 7772 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
23 Correct 4 ms 7768 KB Output is correct
24 Correct 4 ms 7964 KB Output is correct
25 Correct 4 ms 7772 KB Output is correct
26 Correct 3 ms 7516 KB Output is correct
27 Correct 4 ms 7768 KB Output is correct
28 Correct 3 ms 7772 KB Output is correct
29 Correct 4 ms 7772 KB Output is correct
30 Correct 4 ms 7772 KB Output is correct
31 Correct 4 ms 7772 KB Output is correct
32 Correct 4 ms 7776 KB Output is correct
33 Correct 4 ms 7768 KB Output is correct
34 Correct 4 ms 7768 KB Output is correct
35 Correct 4 ms 7772 KB Output is correct
36 Correct 4 ms 7772 KB Output is correct
37 Correct 3 ms 7772 KB Output is correct
38 Correct 4 ms 7772 KB Output is correct
39 Correct 165 ms 24512 KB Output is correct
40 Correct 108 ms 23740 KB Output is correct
41 Correct 118 ms 24000 KB Output is correct
42 Correct 120 ms 24000 KB Output is correct
43 Correct 101 ms 23740 KB Output is correct
44 Correct 104 ms 23996 KB Output is correct
45 Correct 115 ms 23740 KB Output is correct
46 Correct 128 ms 24756 KB Output is correct
47 Correct 109 ms 23996 KB Output is correct
48 Correct 113 ms 24364 KB Output is correct
49 Correct 205 ms 24512 KB Output is correct
50 Correct 186 ms 25020 KB Output is correct
51 Correct 136 ms 25008 KB Output is correct
52 Correct 219 ms 33200 KB Output is correct
53 Correct 194 ms 31156 KB Output is correct
54 Correct 215 ms 32016 KB Output is correct
55 Correct 236 ms 32580 KB Output is correct
56 Correct 269 ms 37552 KB Output is correct
57 Correct 281 ms 39536 KB Output is correct
58 Correct 376 ms 40028 KB Output is correct
59 Correct 311 ms 39936 KB Output is correct
60 Correct 275 ms 38908 KB Output is correct
61 Correct 290 ms 38320 KB Output is correct
62 Correct 241 ms 38948 KB Output is correct
63 Correct 250 ms 39792 KB Output is correct
64 Correct 254 ms 37860 KB Output is correct
65 Correct 287 ms 38172 KB Output is correct
66 Correct 274 ms 39116 KB Output is correct
67 Correct 320 ms 39256 KB Output is correct