Submission #1043139

# Submission time Handle Problem Language Result Execution time Memory
1043139 2024-08-04T02:10:09 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
235 ms 42300 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX_NODE                200005
#define MAX_EDGE                400005
int numNode, numEdge;

int label[MAX_NODE];
vector<int> G[MAX_NODE];
struct Edge{
    int u, v, w;
    Edge(){}
    Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w){}

    int other(int x){
        return (x ^ u ^ v);
    }
} edge[MAX_EDGE];



void dijkstra(int u, int minDist[]){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.emplace(0, u);
    memset(minDist, 0x3f, (numNode + 1) * sizeof(int));
    minDist[u] = 0;
    while(q.size()){
        int du, u; tie(du, u) = q.top(); q.pop();
        if (du > minDist[u]) continue;
        for (int&i : G[u]){
            int v = edge[i].other(u);
            if(minimize(minDist[v], max(minDist[u] + 1, label[v]))){
                q.emplace(minDist[v], v);
            }
        }
    }
}

int minDist[MAX_NODE], rminDist[MAX_NODE];
void process(void){
    cin >> numNode >> numEdge;

    for (int i = 1; i <= numNode; ++i) cin >> label[i];
    for (int i = 1; i <= numEdge; ++i){
        cin >> edge[i].u >> edge[i].v;
        G[edge[i].u].emplace_back(i);
        G[edge[i].v].emplace_back(i);
    }
    dijkstra(1, minDist);
    dijkstra(numNode, rminDist);

    int ans = LINF;
    for (int i = 1; i <= numNode; ++i){
        int cost = max(minDist[i], rminDist[i]) * 2;
        minimize(ans, cost);
    }

    for (int i = 1; i <= numEdge; ++i){
        int u = edge[i].u, v = edge[i].v;
        minimize(ans, max(minDist[u], rminDist[v]) * 2 + 1);
        minimize(ans, max(minDist[v], rminDist[u]) * 2 + 1);
    }
    cout << ans;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}





# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 38 ms 24576 KB Output is correct
3 Correct 43 ms 24916 KB Output is correct
4 Correct 41 ms 25172 KB Output is correct
5 Correct 42 ms 25428 KB Output is correct
6 Correct 47 ms 25476 KB Output is correct
7 Correct 42 ms 25428 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 3 ms 10940 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10800 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 3 ms 10940 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10800 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 2 ms 10844 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 2 ms 10844 KB Output is correct
23 Correct 2 ms 10844 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 2 ms 10844 KB Output is correct
27 Correct 3 ms 10844 KB Output is correct
28 Correct 2 ms 10740 KB Output is correct
29 Correct 2 ms 10844 KB Output is correct
30 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 38 ms 24576 KB Output is correct
3 Correct 43 ms 24916 KB Output is correct
4 Correct 41 ms 25172 KB Output is correct
5 Correct 42 ms 25428 KB Output is correct
6 Correct 47 ms 25476 KB Output is correct
7 Correct 42 ms 25428 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 3 ms 10940 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 2 ms 10844 KB Output is correct
19 Correct 2 ms 10844 KB Output is correct
20 Correct 2 ms 10800 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 2 ms 10844 KB Output is correct
23 Correct 2 ms 10844 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 1 ms 10588 KB Output is correct
27 Correct 2 ms 10844 KB Output is correct
28 Correct 2 ms 10844 KB Output is correct
29 Correct 2 ms 10844 KB Output is correct
30 Correct 2 ms 10844 KB Output is correct
31 Correct 2 ms 10844 KB Output is correct
32 Correct 2 ms 10844 KB Output is correct
33 Correct 2 ms 10844 KB Output is correct
34 Correct 2 ms 10844 KB Output is correct
35 Correct 3 ms 10844 KB Output is correct
36 Correct 2 ms 10740 KB Output is correct
37 Correct 2 ms 10844 KB Output is correct
38 Correct 2 ms 10844 KB Output is correct
39 Correct 99 ms 26524 KB Output is correct
40 Correct 74 ms 25680 KB Output is correct
41 Correct 72 ms 25684 KB Output is correct
42 Correct 73 ms 25856 KB Output is correct
43 Correct 72 ms 25680 KB Output is correct
44 Correct 70 ms 25684 KB Output is correct
45 Correct 74 ms 25608 KB Output is correct
46 Correct 72 ms 25684 KB Output is correct
47 Correct 72 ms 25684 KB Output is correct
48 Correct 71 ms 25640 KB Output is correct
49 Correct 97 ms 26600 KB Output is correct
50 Correct 80 ms 26452 KB Output is correct
51 Correct 76 ms 26440 KB Output is correct
52 Correct 181 ms 34612 KB Output is correct
53 Correct 142 ms 33304 KB Output is correct
54 Correct 128 ms 33340 KB Output is correct
55 Correct 160 ms 33564 KB Output is correct
56 Correct 222 ms 40652 KB Output is correct
57 Correct 190 ms 40892 KB Output is correct
58 Correct 190 ms 41784 KB Output is correct
59 Correct 219 ms 41656 KB Output is correct
60 Correct 186 ms 42300 KB Output is correct
61 Correct 235 ms 41404 KB Output is correct
62 Correct 210 ms 40400 KB Output is correct
63 Correct 177 ms 40492 KB Output is correct
64 Correct 190 ms 40656 KB Output is correct
65 Correct 180 ms 40672 KB Output is correct
66 Correct 206 ms 41432 KB Output is correct
67 Correct 184 ms 40760 KB Output is correct