Submission #937586

# Submission time Handle Problem Language Result Execution time Memory
937586 2024-03-04T09:18:51 Z ByeWorld Factories (JOI14_factories) C++14
Compilation error
0 ms 0 KB
#include "factories.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<ll,ll> pii;
const ll INF = 1e18+10;
const int MAXN = 5e5+10;
const int LOG = 21;

int n;
vector <pii> adj[MAXN];
ll dep[MAXN], up[MAXN], anc[MAXN][LOG+5];
ll x[MAXN], y[MAXN];

void dfs(ll nw, ll par){
	dep[nw] = dep[par]+1;
	anc[nw][0] = par;
	for(auto nx : adj[nw]){
		if(nx.fi == par) continue;
		up[nx.fi] = up[nw]+nx.se;
		dfs(nx.fi, nw);
	}
}

ll LCA(ll x, ll y){
	if(dep[x] > dep[y]) swap(x, y); //gerakin y
	for(int i=LOG-1; i>=0; i--){
		if(dep[anc[y][i]] >= dep[x]) y = anc[y][i]; // dibawah ato sama dengan
	}
	if(x == y) return x;
	for(int i=LOG-1; i>=0; i--){
		if(anc[y][i] != anc[x][i]){
			x = anc[x][i];
			y = anc[y][i];
		}
	}
	return anc[x][0];
}
ll DIST(ll x, ll y){
	ll lca = LCA(x, y);
	return (ll)up[x]+up[y]-2*up[lca];
}

void Init(int N, int A[], int B[], int D[]) {
	n = N;
	for(int i=0; i<n-1; i++){
		A[i]++; B[i]++;
		adj[A[i]].pb({B[i], D[i]}); adj[A[i]].pb({B[i], D[i]});
	}
	up[0] = 0; dep[0] = 0;
	dfs(1, -1);
	for(int i=1; i<LOG; i++){
		for(int j=1; j<=n; j++){
			anc[j][i] = anc[anc[j][i-1]][i-1];
		}
	}
	//cout << LCA(6, 7) << "pp\n";
	//for(int i=1; i<=n; i++) cout << up[i] << " p\n";
}

long long Query(int S, int X[], int T, int Y[]) {
	int s = S, t = T;
	for(int i=1; i<=s; i++) x[i] = X[i-1]+1;
	for(int i=1; i<=t; i++) y[i] = Y[i-1]+1;

	//for(int i=1; i<=s; i++) cout << x[i] << "p\n";
	//for(int i=1; i<=t; i++) cout << y[i] << "pp\n";

	ll mn = INF;
	for(int i=1; i<=s; i++){
		for(int j=1; j<=t; j++){
			int te = DIST(x[i], y[j]);
			mn = min(mn, te);
			//cout << x[i] << ' ' << y[j] << ' '<< DIST(x[i], y[j]) << ' '<< up[x[i]] << ' ' << " x\n";
			assert(te != 0);
		}
	}
	return mn;
}

Compilation message

factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:80:19: error: no matching function for call to 'min(long long int&, int&)'
   80 |    mn = min(mn, te);
      |                   ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from factories.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
factories.cpp:80:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |    mn = min(mn, te);
      |                   ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from factories.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
factories.cpp:80:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |    mn = min(mn, te);
      |                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
factories.cpp:80:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |    mn = min(mn, te);
      |                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
factories.cpp:80:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |    mn = min(mn, te);
      |                   ^