Submission #297735

#TimeUsernameProblemLanguageResultExecution timeMemory
297735MoNsTeR_CuBe통행료 (IOI18_highway)C++17
Compilation error
0 ms0 KiB
#include "highway.h"
    #include <bits/stdc++.h>
    using namespace std;
#define int long long 
    void dfs(int node, int parent, vector< int > &index, vector< vector< pair<int,int> > > &Graph, int &curr, int lastEdge, vector< int > &EdgeToNode){
     
    	for(auto a: Graph[node]){
    		if(a.first == parent) continue;
    		dfs(a.first, node, index, Graph, curr, a.second, EdgeToNode);
    	}	
    	index[curr++] = lastEdge;
    	if(lastEdge != -1) EdgeToNode[lastEdge] = node;
    }
     
    void search(int left, int right, int M, vector< int > &ans, vector< int > &EdgeToNode, vector< int > &index, int mark){
    	if(left == right){
    		ans.push_back(EdgeToNode[index[left]]);
    		return;
    	}
    	vector< int > toAsk(M,0);
    	int mid = (left+right)/2;
    	for(int i = 0; i<= mid; i++){
    		toAsk[index[i]] = 1;
    		//cout << EdgeToNode[index[i]] << ' ';
    	}
    	//cout << endl;
    	int rep = ask(toAsk);
    	if(rep > mark){
    		search(left, mid, M, ans,EdgeToNode,index, mark);
    	}else{
    		search(mid+1, right, M, ans,EdgeToNode,index, mark);
    	}
    }
#undef int
    void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
#define int long long
      int M = U.size();
      vector< vector< pair<int, int> > > Graph(N);
      for(int i = 0; i < M; i++){
    		Graph[U[i]].push_back({V[i],i});
    		Graph[V[i]].push_back({U[i],i});
      }
      
      int curr = 0;
      vector< int > index(N);
      vector< int > EdgeToNode(M+1);
      dfs(0, -1, index, Graph, curr,N, EdgeToNode);
      vector< int > ans;
      vector< int > toAsk(M);
      int mark = ask(toAsk);
      search(0,M-1, M,ans,EdgeToNode,index, mark);
      //cout << ans[0] << endl;
      curr = 0;
      dfs(ans[0],-1,index,Graph,curr,N,EdgeToNode);
      //cout << "N" << endl;
      search(0,M-1, M,ans,EdgeToNode,index, mark);
      //cout << ans[1] << endl;
      assert((int)ans.size() == 2);
      answer(ans[0], ans[1]);
    }

Compilation message (stderr)

highway.cpp: In function 'void search(long long int, long long int, long long int, std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&, long long int)':
highway.cpp:27:20: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   27 |      int rep = ask(toAsk);
      |                    ^~~~~
In file included from highway.cpp:1:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:50:22: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   50 |       int mark = ask(toAsk);
      |                      ^~~~~
In file included from highway.cpp:1:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^