Submission #140330

#TimeUsernameProblemLanguageResultExecution timeMemory
140330XmtosXHighway Tolls (IOI18_highway)C++17
51 / 100
1433 ms262148 KiB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=90005;
int n,m,par[MAXN];
vector <int> v[MAXN];
vector <pair<int,int> > vv;
map <pair<int,int>, int> r;
long long ANS;
bool block[MAXN];
void dfs (int x,int p,int l)
{
    vv.push_back({l,x});
    par[x]=p;
    for (int i=0;i<v[x].size();i++)
    {
        if (v[x][i]!=p&&!block[v[x][i]])
        {
            dfs(v[x][i],x,l+1);
        }
    }
}
void find_pair (int N, vector<int> U, vector<int> V, int A, int B)
{
    n=N;
    m=U.size();
    vector<int> w;
    w.resize(m);
    ANS=ask(w);
    int low=0,high=m-1,ans,mid;
    while (low<=high)
    {
        mid=(high+low)/2;
        if (low==high)
        {
            ans=mid;
            break;
        }
        if (mid==low)
            mid++;
        for (int i=0;i<m;i++)
            w[i]=0;
        for (int i=mid;i<=high;i++)
        {
            w[i]=1;
        }
        if (ANS!=ask(w))
        {
            low=mid;
        }
        else
            high=mid-1;
    }
    for (int i=0;i<m;i++)
    {
        v[U[i]].push_back(V[i]);
        v[V[i]].push_back(U[i]);
        r[{U[i],V[i]}]=i;
        r[{V[i],U[i]}]=i;
    }
    block[U[ans]]=1;
    block[V[ans]]=1;
    int an[2];
    int u[2]={U[ans],V[ans]};
    for (int q=0;q<2;q++)
    {
        vv.clear();
        dfs(u[q],u[1-q],1);
        if (vv.size()==1)
        {
            an[q]=vv[0].second;
            continue;
        }
        low=0,high=vv.size(),mid,ans=-1;
        while (low<=high)
        {
            for (int i=0;i<w.size();i++)
                w[i]=0;
            mid=(low+high)/2;
            for (int i=mid;i<vv.size();i++)
            {
                int a=vv[i].second;
                w[r[{a,par[a]}]]=1;
            }
            if (ask(w)!=ANS)
            {
                ans=vv[mid].second;
                low=mid+1;
            }
            else
                high=mid-1;
        }
        an[q]=ans;
    }
    answer(an[0],an[1]);
}

Compilation message (stderr)

highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v[x].size();i++)
                  ~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:74:39: warning: right operand of comma operator has no effect [-Wunused-value]
         low=0,high=vv.size(),mid,ans=-1;
                                       ^
highway.cpp:77:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i=0;i<w.size();i++)
                          ~^~~~~~~~~
highway.cpp:80:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i=mid;i<vv.size();i++)
                            ~^~~~~~~~~~
highway.cpp:61:16: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
     block[U[ans]]=1;
                ^
#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...