답안 #766040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766040 2023-06-25T09:13:53 Z t6twotwo 통행료 (IOI18_highway) C++17
100 / 100
208 ms 11140 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    int M = U.size(), lo, hi;
    ll s = ask(vector<int>(M));
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < M; i++) {
        adj[U[i]].emplace_back(V[i], i);
        adj[V[i]].emplace_back(U[i], i);
    }
    vector<int> W(M);
    lo = 0, hi = M - 1;
    while (lo < hi) {
        int mi = (lo + hi) / 2;
        auto w = W;
        for (int i = 0; i <= mi; i++) {
            w[i] = 1;
        }
        if (ask(w) == s) {
            W = w;
            lo = mi + 1;
        } else {
            hi = mi;
        }
    }
    auto bfs = [&](int s) {
        vector<int> dis(N, -1);
        dis[s] = 0;
        queue<int> q;
        q.push(s);
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (auto [y, z] : adj[x]) {
                if (dis[y] == -1) {
                    dis[y] = dis[x] + 1;
                    q.push(y);
                }
            }
        }
        return dis;
    };
    int P = U[lo], Q = V[lo];
    auto d0 = bfs(P);
    auto d1 = bfs(Q);
    vector<int> cand;
    for (int i = 0; i < N; i++) {
        if (d0[i] < d1[i]) {
            cand.push_back(i);
        }
    }
    sort(cand.begin(), cand.end(), [&](int i, int j) {
        return d0[i] < d0[j];
    });
    lo = 0, hi = cand.size() - 1;
    while (lo < hi) {
        int mi = (lo + hi) / 2;
        vector<int> w(M);
        for (int i = mi + 1; i < cand.size(); i++) {
            for (auto [y, z] : adj[cand[i]]) {
                w[z] = 1;
            }
        }
        if (ask(w) == s) {
            hi = mi;
        } else {
            lo = mi + 1;
        }
    }
    int S = cand[lo];
    cand.clear();
    for (int i = 0; i < N; i++) {
        if (d1[i] < d0[i]) {
            cand.push_back(i);
        }
    }
    sort(cand.begin(), cand.end(), [&](int i, int j) {
        return d1[i] < d1[j];
    });
    lo = 0, hi = cand.size() - 1;
    while (lo < hi) {
        int mi = (lo + hi) / 2;
        vector<int> w(M);
        for (int i = mi + 1; i < cand.size(); i++) {
            for (auto [y, z] : adj[cand[i]]) {
                w[z] = 1;
            }
        }
        if (ask(w) == s) {
            hi = mi;
        } else {
            lo = mi + 1;
        }
    }
    answer(S, cand[lo]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:61:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int i = mi + 1; i < cand.size(); i++) {
      |                              ~~^~~~~~~~~~~~~
highway.cpp:86:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int i = mi + 1; i < cand.size(); i++) {
      |                              ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 12 ms 1396 KB Output is correct
3 Correct 94 ms 9144 KB Output is correct
4 Correct 117 ms 9148 KB Output is correct
5 Correct 120 ms 9140 KB Output is correct
6 Correct 97 ms 9156 KB Output is correct
7 Correct 85 ms 9148 KB Output is correct
8 Correct 95 ms 9140 KB Output is correct
9 Correct 106 ms 9136 KB Output is correct
10 Correct 99 ms 9136 KB Output is correct
11 Correct 95 ms 8540 KB Output is correct
12 Correct 92 ms 8632 KB Output is correct
13 Correct 135 ms 8552 KB Output is correct
14 Correct 111 ms 8644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1180 KB Output is correct
2 Correct 18 ms 2092 KB Output is correct
3 Correct 33 ms 2988 KB Output is correct
4 Correct 97 ms 8524 KB Output is correct
5 Correct 70 ms 8532 KB Output is correct
6 Correct 67 ms 8468 KB Output is correct
7 Correct 91 ms 8552 KB Output is correct
8 Correct 97 ms 8676 KB Output is correct
9 Correct 89 ms 8484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 14 ms 1232 KB Output is correct
3 Correct 100 ms 7164 KB Output is correct
4 Correct 103 ms 9148 KB Output is correct
5 Correct 98 ms 9136 KB Output is correct
6 Correct 128 ms 9140 KB Output is correct
7 Correct 119 ms 9156 KB Output is correct
8 Correct 90 ms 9132 KB Output is correct
9 Correct 101 ms 9428 KB Output is correct
10 Correct 103 ms 9140 KB Output is correct
11 Correct 114 ms 8568 KB Output is correct
12 Correct 103 ms 8516 KB Output is correct
13 Correct 98 ms 8492 KB Output is correct
14 Correct 112 ms 8552 KB Output is correct
15 Correct 91 ms 9148 KB Output is correct
16 Correct 121 ms 9140 KB Output is correct
17 Correct 110 ms 8548 KB Output is correct
18 Correct 115 ms 8556 KB Output is correct
19 Correct 93 ms 9248 KB Output is correct
20 Correct 96 ms 8532 KB Output is correct
21 Correct 68 ms 9284 KB Output is correct
22 Correct 112 ms 9364 KB Output is correct
23 Correct 81 ms 9244 KB Output is correct
24 Correct 117 ms 9180 KB Output is correct
25 Correct 110 ms 8740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1288 KB Output is correct
2 Correct 17 ms 1312 KB Output is correct
3 Correct 112 ms 9548 KB Output is correct
4 Correct 141 ms 10020 KB Output is correct
5 Correct 133 ms 10948 KB Output is correct
6 Correct 167 ms 11044 KB Output is correct
7 Correct 158 ms 11056 KB Output is correct
8 Correct 143 ms 11056 KB Output is correct
9 Correct 147 ms 7512 KB Output is correct
10 Correct 97 ms 7996 KB Output is correct
11 Correct 137 ms 8716 KB Output is correct
12 Correct 137 ms 10012 KB Output is correct
13 Correct 143 ms 10616 KB Output is correct
14 Correct 208 ms 11068 KB Output is correct
15 Correct 167 ms 11088 KB Output is correct
16 Correct 135 ms 8552 KB Output is correct
17 Correct 81 ms 9456 KB Output is correct
18 Correct 90 ms 9536 KB Output is correct
19 Correct 87 ms 9464 KB Output is correct
20 Correct 119 ms 9544 KB Output is correct
21 Correct 153 ms 11004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1232 KB Output is correct
2 Correct 10 ms 1296 KB Output is correct
3 Correct 123 ms 9584 KB Output is correct
4 Correct 147 ms 9780 KB Output is correct
5 Correct 121 ms 10032 KB Output is correct
6 Correct 167 ms 11080 KB Output is correct
7 Correct 106 ms 9528 KB Output is correct
8 Correct 118 ms 9668 KB Output is correct
9 Correct 124 ms 9932 KB Output is correct
10 Correct 149 ms 11076 KB Output is correct
11 Correct 178 ms 10936 KB Output is correct
12 Correct 150 ms 11076 KB Output is correct
13 Correct 138 ms 8808 KB Output is correct
14 Correct 124 ms 7980 KB Output is correct
15 Correct 98 ms 8804 KB Output is correct
16 Correct 158 ms 7924 KB Output is correct
17 Correct 104 ms 8796 KB Output is correct
18 Correct 154 ms 7928 KB Output is correct
19 Correct 168 ms 9996 KB Output is correct
20 Correct 132 ms 10616 KB Output is correct
21 Correct 168 ms 11096 KB Output is correct
22 Correct 183 ms 11028 KB Output is correct
23 Correct 201 ms 10944 KB Output is correct
24 Correct 144 ms 11080 KB Output is correct
25 Correct 187 ms 11120 KB Output is correct
26 Correct 136 ms 11052 KB Output is correct
27 Correct 95 ms 9568 KB Output is correct
28 Correct 105 ms 9376 KB Output is correct
29 Correct 90 ms 9632 KB Output is correct
30 Correct 115 ms 9492 KB Output is correct
31 Correct 74 ms 9416 KB Output is correct
32 Correct 100 ms 9360 KB Output is correct
33 Correct 138 ms 9592 KB Output is correct
34 Correct 84 ms 9464 KB Output is correct
35 Correct 69 ms 9424 KB Output is correct
36 Correct 134 ms 9340 KB Output is correct
37 Correct 105 ms 9540 KB Output is correct
38 Correct 88 ms 9524 KB Output is correct
39 Correct 193 ms 11140 KB Output is correct
40 Correct 169 ms 10904 KB Output is correct
41 Correct 118 ms 10932 KB Output is correct
42 Correct 194 ms 11056 KB Output is correct