답안 #1005176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005176 2024-06-22T08:28:40 Z Mardonbekhazratov 경주 (Race) (IOI11_race) C++17
컴파일 오류
0 ms 0 KB
#include "race.h"
#include<bits/stdc++.h>

using namespace std;

int n,k,ans;
vector<vector<pair<int,int>>>v;

void dfs(int x,int p,long long dis,int cnt){
	if(dis>=k){
		if(dis==k) ans=min(ans,cnt);
		return;
	}
	for(auto [z,w]:v[x]){
		if(z!=p) dfs(z,x,dis+w,cnt+1);
	}
}

void solve(int x){
	queue<array<int,4>>q;
	q.push(x);
	while(!q.empty()){
		auto [x,p,dis,cnt]=q.front();
		q.pop();
		if(dis==k){
			ans=min(ans,cnt);
			continue;
		}
		for(auto [z,w]:v[x]){
			if(z!=p && dis+w<=k){
				q.push({z,x,dis+w,cnt+1});
			} 
		}
	}
}

int best_path(int N, int K, int H[][2], int L[]){
	n=N;
	k=K;
	vector<long long>pref(n);
	pref[0]=0;
	v.resize(n);
	bool sub1=true;
	for(int i=0;i<n-1;i++){
		v[H[i][0]].push_back({H[i][1],L[i]});
		v[H[i][1]].push_back({H[i][0],L[i]});
		pref[i+1]=pref[i]+L[i];
		if(H[i][0]!=i || H[i][1]!=i+1) sub1=false;
	}
	ans=n;
	if(sub1){
		for(int i=0;i<n-1;i++){
			auto pos=lower_bound(pref.begin(),pref.end(),pref[i]+K)-pref.begin();
			if(pos!=n && pref[pos]-pref[i]==K) ans=min(ans,(int)pos-i);
		}
		return (ans==n ? -1 : ans);
	}
	for(int i=0;i<n;i++){
		solve(i);
	}
	return (ans==n ? -1 : ans);
}

Compilation message

race.cpp: In function 'void solve(int)':
race.cpp:21:10: error: no matching function for call to 'std::queue<std::array<int, 4> >::push(int&)'
   21 |  q.push(x);
      |          ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::array<int, 4>; _Sequence = std::deque<std::array<int, 4>, std::allocator<std::array<int, 4> > >; std::queue<_Tp, _Sequence>::value_type = std::array<int, 4>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::array<int, 4>&'}
  265 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::array<int, 4>; _Sequence = std::deque<std::array<int, 4>, std::allocator<std::array<int, 4> > >; std::queue<_Tp, _Sequence>::value_type = std::array<int, 4>]'
  270 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:270:25: note:   no known conversion for argument 1 from 'int' to 'std::queue<std::array<int, 4> >::value_type&&' {aka 'std::array<int, 4>&&'}
  270 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~