Submission #115521

# Submission time Handle Problem Language Result Execution time Memory
115521 2019-06-08T04:04:55 Z onjo0127 Highway Tolls (IOI18_highway) C++11
Compilation error
0 ms 0 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

vector<pii> adj[90009];
int dep[90009], pid[90009];
long long gi;

void go(int x, int p, int d, int id) {
    dep[x] = d; pid[x] = id;
    for(auto& it: adj[x]) if(it.first != p) go(it.first, x, d+1, it.second);
}

void solveRoot(int N, vector<int> U, vector<int> V, int A, int B, int root) {
    int M = U.size();
    go(root, root, 0, -1);
    vector<int> W(M, 0);
    int l = 1, r = N-1;
    while(l <= r) {
        W = vector<int>(M, 0);
        int m = l+r >> 1;
        for(int i=0; i<N; i++) {
            if(dep[i] >= m) W[pid[i]] = 1;
        }
        long long t = ask(W);
        if(t != gi) l = m+1;
        else r = m-1;
    }
    vector<int> P;
    for(int i=0; i<N; i++) if(dep[i] == r) P.push_back(i);
    while((int)P.size() > 1) {
        vector<int> NP;
        W = vector<int>(M, 0);
        for(int i=0; i<(int)P.size()/2; i++) W[pid[P[i]]] = 1;
        long long t = ask(W);
        if(t != gi) for(int i=0; i<(int)P.size()/2; i++) NP.push_back(P[i]);
        else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
        P = NP;
    }
    answer(root, P[0]);
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    int M = U.size();
    for(int i=0; i<M; i++) {
        adj[U[i]].push_back({V[i], i});
        adj[V[i]].push_back({U[i], i});
    }
    go(0, 0, 0, -1);
    vector<int> W(M, 0); gi = ask(W);
    int l = 1, r = N-1;
    while(l <= r) {
        W = vector<int>(M, 0);
        int m = l+r >> 1;
        for(int i=0; i<N; i++) {
            if(dep[i] >= m) W[pid[i]] = 1;
        }
        long long t = ask(W);
        if(t != gi) l = m+1;
        else r = m-1;
    }
    vector<int> P;
    for(int i=0; i<N; i++) if(dep[i] == r) P.push_back(i);
    while((int)P.size() > 1) {
        vector<int> NP;
        W = vector<int>(M, 0);
        for(int i=0; i<(int)P.size()/2; i++) W[pid[P[i]]] = 1;
        long long t = ask(W);
        if(t != gi) for(int i=0; i<(int)P.size()/2; i++) NP.push_back(P[i]);
        else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
        P = NP;4 
    }
    solveRoot(N, U, V, A, B, P[0]);
}

Compilation message

highway.cpp: In function 'void solveRoot(int, std::vector<int>, std::vector<int>, int, int, int)':
highway.cpp:22:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
highway.cpp:38:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
                                         ~^~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:55:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
highway.cpp:71:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
                                         ~^~~~~~~~~
highway.cpp:73:5: error: expected ';' before '}' token
     }
     ^
highway.cpp:73:5: warning: statement has no effect [-Wunused-value]