제출 #1149037

#제출 시각아이디문제언어결과실행 시간메모리
1149037NomioConstruction Project 2 (JOI24_ho_t2)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#define s second
#define f first
#define plli pair<ll, int>
#define pill pair<int, ll>

using namespace std;
using ll = long long;

int n, m, s, t;
ll l, k;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> s >> t >> l >> k;
	s--, t--;
	vector<plli> adj[n]; 
	for(int i = 0; i < m; i++) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		adj[a].push_back({b, c});
		adj[b].push_back({a, c});
	}
	priority_queue<plli, vector<plli>, greater<plli>> pq;
	vector<ll> dis(n, 1e18);
	dis[s] = 0;
	pq.push({0, s});
	while(!pq.empty()) {
		ll dist = pq.top().f;
		int a = pq.top().s;
		pq.pop();
		if(dist != dis[a]) continue;
		for(plli p : adj[a]) {
			ll c = p.s;
			int b = p.f;
			if(dist + c < dis[b]) {
				dis[b] = dist + c;
				pq.push({dis[b], b});
			}
		}	
	}
	if(dis[t] <= k) {
		cout << 1LL * n * (n - 1) / 2 << '\n';
		return 0;
	}
	vector<ll> dis1(n, 1e18);
	dis1[t] = 0;
	pq.push({0, t});
	while(!pq.empty()) {
		ll dist = pq.top().f;
		int a = pq.top().s;
		pq.pop();
		if(dist != dis1[a]) continue;
		for(plli p : adj[a]) {
			ll c = p.s;
			int b = p.f;
			if(dist + c < dis1[b]) {
				dis1[b] = dist + c;
				pq.push({dis1[b], b});
			}
		}	
	}
	sort(dis1.begin(), dis1.end());
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
	}
	cout << ans << '\n';
	return 0;
}

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

Main.cpp: In function 'int main()':
Main.cpp:69:27: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   69 |                 ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:69:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   69 |                 ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:69:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   69 |                 ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
Main.cpp:69:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |                 ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
Main.cpp:69:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |                 ans += max(0LL, (upper_bound(dis1.begin(), dis1.end(), k - l - dis[i]) - dis1.begin()));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~