제출 #1145420

#제출 시각아이디문제언어결과실행 시간메모리
1145420Issa통행료 (IOI18_highway)C++20
51 / 100
69 ms10720 KiB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 1e5 + 100;

int n;
vector<pii> g[maxn];
int p[maxn];
int f[maxn];
ll dist;

int calc(vector<int> s){
    int v = -1;
    for(int l = 0, r = s.size()-1; l <= r;){
        int mid = (l + r) >> 1;
        vector<int> q(n-1, 0);
        for(int i = 0; i <= mid; i++){
            q[f[s[i]]] = 1;
        } if(ask(q) == dist) l = mid + 1;
        else r = mid - 1, v = s[mid];
    } return v;
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N;
    dist = ask(vector<int>(N-1, 0));
    for(int i = 0; i < n - 1; i++){
        int a = U[i], b = V[i];
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    vector<int> s;
    queue<int> q;
    q.push(0);
    while(q.size()){
        int v = q.front();
        q.pop();
        for(auto [to, i]: g[v]){
            if(to != p[v]){
                p[to] = v;
                f[to] = i;
                q.push(to);
                s.push_back(to);
            }
        }
    } reverse(s.begin(), s.end());
    int a = calc(s);
    vector<int> ns;
    int i = a;
    for(int v: s){
        if(v == i){
            i = p[i];
            continue;
        } ns.push_back(v);
    } int b = calc(ns);
    if(b == -1){
        ns.clear();
        for(int i = a; i; i = p[i]){
            ns.push_back(i);
        } reverse(ns.begin(), ns.end());
        b = p[calc(ns)];
    } answer(a, b);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...