답안 #1081770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081770 2024-08-30T10:20:15 Z vladilius 통행료 (IOI18_highway) C++17
0 / 100
12 ms 5812 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
    int m = (int) U.size();
    vector<pii> g[n + 1];
    for (int i = 0; i < m; i++){
        U[i]++; V[i]++;
        g[U[i]].pb({V[i], i});
        g[V[i]].pb({U[i], i});
    }
    
    vector<int> w(m);

    ll nl = ask(w);
    vector<int> all;
    for (int i = 0; i < m; i++) all.pb(i);
    
    while (all.size() > 1){
        int k = (int) all.size() / 2;
        fill(w.begin(), w.end(), 1);
        for (int i = k; i < all.size(); i++) w[all[i]] = 0;
        
        if (ask(w) == nl){
            reverse(all.begin(), all.end());
            k = (int) all.size() - k;
            while (all.size() > k) all.pop_back();
        }
        else {
            while (all.size() > k) all.pop_back();
        }
    }
    
    int x = all[0];
    
    vector<bool> used(n + 1);
    vector<int> ed = {x};
    queue<int> q;
    q.push(V[x]);
    q.push(U[x]);
    used[V[x]] = used[U[x]] = 1;
    while (!q.empty()){
        int f = q.front(); q.pop();
        for (auto [i, j]: g[f]){
            if (used[i] || j == x) continue;
            used[i] = 1;
            q.push(i);
            ed.pb(j);
        }
    }
    
    fill(w.begin(), w.end(), 1);
    
    auto cl = [&](){
        for (int i: ed) w[i] = 0;
    };
    
    cl();
    vector<pii> t[n + 1];
    for (int i: ed){
        t[U[i]].pb({V[i], i});
        t[V[i]].pb({U[i], i});
    }
    
    vector<int> d(n + 1), p(n + 1), pe(n + 1);
    function<void(int, int, vector<int>&, vector<int>&)> dfs = [&](int v, int pr, vector<int>& ed, vector<int>& q){
        q.pb(v);
        p[v] = pr;
        for (auto [i, j]: t[v]){
            if (i == pr || j == x) continue;
            d[i] = d[v] + 1;
            pe[i] = j;
            ed.pb(j);
            dfs(i, v, ed, q);
        }
    };
    
    vector<int> d1, d2, t1, t2;
    dfs(U[x], 0, d1, t1);
    dfs(V[x], 0, d2, t2);
    
    int dist = (int) (ask(w) / A);
    
    auto add = [&](int x, int y){
        while (y != x && !w[pe[y]]){
            w[pe[y]] = 1;
            y = p[y];
        }
    };
    
    auto solve = [&](int v, vector<int>& x1, vector<int>& x2, vector<int>& vv){
        cl();
        for (int i: x2) w[i] = 1;
        int ds = (int) ((ask(w) + B - A - 1LL * dist * B) / (A - B));
        
        vector<int> all;
        for (int i: vv){
            if (d[i] == ds){
                all.pb(i);
            }
        }
        
        while (all.size() > 1){
            int k = (int) all.size() / 2;
            cl();
            for (int i = 0; i < k; i++){
                add(v, all[i]);
            }
            ll sm = ask(w);
            if (sm == (1LL * A * (dist - ds) + 1LL * B * ds)){
                while (all.size() > k){
                    all.pop_back();
                }
            }
            else {
                reverse(all.begin(), all.end());
                k = (int) all.size() - k;
                while (all.size() > k) all.pop_back();
            }
        }
        
        return (all[0] - 1);
    };
    
    answer(solve(U[x], d1, d2, t1), solve(V[x], d2, d1, t2));
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:28:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (int i = k; i < all.size(); i++) w[all[i]] = 0;
      |                         ~~^~~~~~~~~~~~
highway.cpp:33:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |             while (all.size() > k) all.pop_back();
      |                    ~~~~~~~~~~~^~~
highway.cpp:36:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |             while (all.size() > k) all.pop_back();
      |                    ~~~~~~~~~~~^~~
highway.cpp: In lambda function:
highway.cpp:117:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  117 |                 while (all.size() > k){
      |                        ~~~~~~~~~~~^~~
highway.cpp:124:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  124 |                 while (all.size() > k) all.pop_back();
      |                        ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2156 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 2136 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -