답안 #965393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965393 2024-04-18T12:36:03 Z Warinchai 통행료 (IOI18_highway) C++14
컴파일 오류
0 ms 0 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>adj[100000];
void dfs(int u,vector<int>&x,vector<int>&nodes,int p,int val){
    x.push_back(val);
    nodes.push_back(u);
    for(auto v:adj[u])if(v.first!=p)dfs(v.first,x,nodes,u,v.second);
}
void subtree(int n,vector<int>u,vector<int>v,int a,int b,int cost){
    int st=0,en=u.size()-1,ans=0;
    while(st<=en){
        int m=(st+en)/2;
        vector<int>temp;
        for(int i=0;i<m;i++)temp.push_back(1);
        for(int i=m;i<n;i++)temp.push_back(0);
        if(ask(temp)>cost){
            en=m-1;
            ans=m;
        }else{
            st=m+1;
        }
    }
    int a=u[ans];
    int b=v[ans];
    vector<int>temp;
    vector<int>side1;
    vector<int>side2;
    vector<int>node1;
    vector<int>node2;
    for(int i=0;i<n;i++)temp.push_back(0);
    dfs(a,side1,node1,b,ans);
    dfs(b,side2,node2,a,ans);
    for(auto x:side1)temp[x]=1;
    int cost1=ask(temp);
    for(auto x:side1)temp[x]=0;
    for(auto x:side2)temp[x]=1;
    int cost2=ask(temp);
    for(int i=0;i<n;i++)temp[i]=0;
    int n1,n2;
    st=0,en=side1.size();
    for(int i=0;i<n;i++)temp[i]=0;
    while(st<=en){
        int m=(st+en)/2;
        for(int i=0;i<m;i++)temp[side1[i]]=1;
        if(ask(temp)<=cost1){
            st=m+1;
            n1=m;
        }else{
            en=m-1;
        }
        for(int i=0;i<m;i++)temp[side1[i]]=0;
    }
    st=0,en=side2.size();
    while(st<=en){
        int m=(st+en)/2;
        for(int i=0;i<m;i++)temp[side2[i]]=1;
        if(ask(temp)<=cost2){
            st=m+1;
            n2=m;
        }else{
            en=m-1;
        }
        for(int i=0;i<m;i++)temp[side2[i]]=0;
    }
    answer(node1[n1],node2[n2]);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    vector<int>temp;
    for(int i=0;i<N;i++)temp.push_back(0);
    if(U.size()!=N-1)return answer(rand()%N,rand()%N);
    else return subtree(N,U,V,A,B,ask(temp));
}

Compilation message

highway.cpp: In function 'void subtree(int, std::vector<int>, std::vector<int>, int, int, int)':
highway.cpp:24:9: error: declaration of 'int a' shadows a parameter
   24 |     int a=u[ans];
      |         ^
highway.cpp:10:50: note: 'int a' previously declared here
   10 | void subtree(int n,vector<int>u,vector<int>v,int a,int b,int cost){
      |                                              ~~~~^
highway.cpp:25:9: error: declaration of 'int b' shadows a parameter
   25 |     int b=v[ans];
      |         ^
highway.cpp:10:56: note: 'int b' previously declared here
   10 | void subtree(int n,vector<int>u,vector<int>v,int a,int b,int cost){
      |                                                    ~~~~^
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:71:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |     if(U.size()!=N-1)return answer(rand()%N,rand()%N);
      |        ~~~~~~~~^~~~~