제출 #463538

#제출 시각아이디문제언어결과실행 시간메모리
463538KhizriTraffic (IOI10_traffic)C++17
컴파일 에러
0 ms0 KiB
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back		 
#define F first																 
#define S second 															 
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
const int mxn=1e6+5;
int a[mxn],b[mxn];
vector<int>vt[mxn];
ll dfs(int u,int p,int arr[]){
	int ans=0;
	for(int v:vt[u]){
		if(v!=p){
			ans=max(ans,dfs(v,u,arr));
		}
	}
	return ans+arr[u];
}
int LocateCentre(int n, int arr[], int S[], int D[]) {
	bool q=true;
	for(int i=0;i<n-1;i++){
		if(S[i]!=i||D[i]!=i+1){
			q=false;
		}
	}
	if(q){
		a[0]=arr[0];
		for(int i=1;i<n;i++){
			a[i]=a[i-1]+arr[i];
		}
		b[n-1]=arr[n-1];
		for(int i=n-2;i>=0;i--){
			b[i]=b[i+1]+arr[i];
		}
		int ans=2000000000,k=0;
		for(int i=0;i<n;i++){
			int x=0;
			if(i-1>=0){
				x=a[i-1];
				//cout<<a[i-1]<<' ';
			}
			if(i+1<n){
				x=max(x,b[i+1]);
				//cout<<b[i+1]<<' ';
			}
			//cout<<endl;
			//cout<<x<<' ';
			if(x<ans){
				k=i;
				ans=x;
			}
		}
		return k;
	}
	
	for(int i=0;i<n-1;i++){
		vt[S[i]].pb(D[i]);
		vt[D[i]].pb(S[i]);
	}
	ll maxs=INF,kk=0;
	for(int i=0;i<n;i++){
		ll sum=dfs(i,-1,arr)-arr[i];
		if(sum<maxs){
			maxs=sum;
			kk=i;
		}
	}
	return kk;
}

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

traffic.cpp: In function 'long long int dfs(int, int, int*)':
traffic.cpp:23:28: error: no matching function for call to 'max(int&, long long int)'
   23 |    ans=max(ans,dfs(v,u,arr));
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from traffic.cpp:2:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
traffic.cpp:23:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   23 |    ans=max(ans,dfs(v,u,arr));
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from traffic.cpp:2:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
traffic.cpp:23:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   23 |    ans=max(ans,dfs(v,u,arr));
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from traffic.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
traffic.cpp:23:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   23 |    ans=max(ans,dfs(v,u,arr));
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from traffic.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
traffic.cpp:23:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   23 |    ans=max(ans,dfs(v,u,arr));
      |                            ^