답안 #1043140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043140 2024-08-04T02:10:30 Z Whisper Airplane (NOI23_airplane) C++17
100 / 100
212 ms 35064 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);
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 36 ms 21376 KB Output is correct
3 Correct 37 ms 21248 KB Output is correct
4 Correct 40 ms 21332 KB Output is correct
5 Correct 39 ms 21328 KB Output is correct
6 Correct 40 ms 21328 KB Output is correct
7 Correct 40 ms 21176 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 1 ms 10724 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 1 ms 10724 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 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 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10844 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 2 ms 10844 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 3 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 36 ms 21376 KB Output is correct
3 Correct 37 ms 21248 KB Output is correct
4 Correct 40 ms 21332 KB Output is correct
5 Correct 39 ms 21328 KB Output is correct
6 Correct 40 ms 21328 KB Output is correct
7 Correct 40 ms 21176 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 1 ms 10724 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 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 10588 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 10844 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 10844 KB Output is correct
34 Correct 2 ms 10844 KB Output is correct
35 Correct 2 ms 10844 KB Output is correct
36 Correct 2 ms 10844 KB Output is correct
37 Correct 2 ms 10844 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
39 Correct 98 ms 22268 KB Output is correct
40 Correct 69 ms 22192 KB Output is correct
41 Correct 69 ms 22236 KB Output is correct
42 Correct 67 ms 22352 KB Output is correct
43 Correct 69 ms 22204 KB Output is correct
44 Correct 68 ms 22376 KB Output is correct
45 Correct 71 ms 22352 KB Output is correct
46 Correct 70 ms 22352 KB Output is correct
47 Correct 79 ms 22356 KB Output is correct
48 Correct 69 ms 22204 KB Output is correct
49 Correct 86 ms 22232 KB Output is correct
50 Correct 81 ms 22356 KB Output is correct
51 Correct 75 ms 22272 KB Output is correct
52 Correct 171 ms 28972 KB Output is correct
53 Correct 128 ms 28984 KB Output is correct
54 Correct 138 ms 28928 KB Output is correct
55 Correct 148 ms 28952 KB Output is correct
56 Correct 209 ms 35024 KB Output is correct
57 Correct 195 ms 35004 KB Output is correct
58 Correct 189 ms 35004 KB Output is correct
59 Correct 196 ms 35004 KB Output is correct
60 Correct 212 ms 34948 KB Output is correct
61 Correct 188 ms 35008 KB Output is correct
62 Correct 170 ms 35040 KB Output is correct
63 Correct 190 ms 34984 KB Output is correct
64 Correct 187 ms 35020 KB Output is correct
65 Correct 184 ms 34868 KB Output is correct
66 Correct 184 ms 35064 KB Output is correct
67 Correct 191 ms 35000 KB Output is correct