제출 #438957

#제출 시각아이디문제언어결과실행 시간메모리
438957leinad2통행료 (IOI18_highway)C++17
100 / 100
282 ms11004 KiB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int> >adj[90010];
int vis[90010];
void find_pair(int N, vector<int>U, vector<int>V, int A, int B)
{
    int M=U.size();
    vector<int>w(M);long long X=ask(w);
    for(int i=0;i<M;i++)
    {
        adj[U[i]].push_back({V[i], i});
        adj[V[i]].push_back({U[i], i});
    }
    int s=0;int e=M-1;
    while(s<e)
    {
        int m=s+e>>1;
        for(int i=0;i<M;i++)w[i]=0;
        for(int i=0;i<=m;i++)w[i]=1;
        if(ask(w)>X)e=m;
        else s=m+1;
    }
    int S=U[s], E=V[s];
    queue<pair<int, int> >q;
    q.push({S, 0});
    q.push({E, 1});
    vis[S]=vis[E]=1;
    vector<int>v1, v2;
    while(q.size())
    {
        int a=q.front().first;int b=q.front().second;q.pop();
        if(b==0)v1.push_back(a);else v2.push_back(a);
        for(int i=0;i<adj[a].size();i++)
        {
            int p=adj[a][i].first;
            if(vis[p])continue;
            vis[p]=1;q.push({p, b});
        }
    }
    int a=0;int b=v1.size()-1;
    while(a<b)
    {
        int chk[90010]={};
        int m=a+b+1>>1;
        for(int i=0;i<N;i++)chk[i]=0;
        for(int i=m;i<v1.size();i++)chk[v1[i]]=1;
        for(int i=0;i<M;i++)w[i]=(chk[U[i]]!=chk[V[i]]);
        if(ask(w)>X)a=m;
        else b=m-1;
    }
    int ans1=v1[a];
    a=0;b=v2.size()-1;
    while(a<b)
    {
        int chk[90010]={};
        int m=a+b+1>>1;
        for(int i=0;i<N;i++)chk[i]=0;
        for(int i=m;i<v2.size();i++)chk[v2[i]]=1;
        for(int i=0;i<M;i++)w[i]=(chk[U[i]]!=chk[V[i]]);
        if(ask(w)>X)a=m;
        else b=m-1;
    }
    int ans2=v2[a];
    answer(ans1, ans2);
}

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:18:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |         int m=s+e>>1;
      |               ~^~
highway.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i=0;i<adj[a].size();i++)
      |                     ~^~~~~~~~~~~~~~
highway.cpp:45:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |         int m=a+b+1>>1;
      |               ~~~^~
highway.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=m;i<v1.size();i++)chk[v1[i]]=1;
      |                     ~^~~~~~~~~~
highway.cpp:57:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |         int m=a+b+1>>1;
      |               ~~~^~
highway.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i=m;i<v2.size();i++)chk[v2[i]]=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...