Submission #879089

# Submission time Handle Problem Language Result Execution time Memory
879089 2023-11-26T10:32:50 Z serifefedartar Factories (JOI14_factories) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 5e5 + 100;

vector<vector<pair<int,int>>> graph;
int marked[MAXN], sz[MAXN], up[LOGN][MAXN], depth[MAXN];
ll depth_dist[MAXN], ans[MAXN];

int get_sz(int node, int parent) {
	sz[node] = 1;
	for (auto u : graph[node]) {
		if (u.f == parent || marked[u.f])
			continue;
		sz[node] += get_sz(u.f, node);
	}
	return sz[node];
}

int find_centro(int node, int parent, int n) {
	for (auto u : graph[node]) {
		if (u.f != parent && !marked[u.f] && sz[u.f] * 2 > sz[node])
			return find_centro(u.f, node, n);	
	}
	return node;
}

void decompose(int node, bool q) {
	int n = get_sz(node, node);
	int centro = find_centro(node, node, n);

	marked[centro] = true;
	if (q)
		par[centro] = -1;
	else
		par[centro] = node;

	for (auto u : graph[centro]) {
		if (u.f != parent && !marked[u.f])
			decompose(u.f, false);
	}
}

void dfs(int node, int parent) {
	for (auto u : graph[node]) {
		if (u.f == parent)
			continue;
		depth[u.f] = depth[node] + 1;
		depth_dist[u.f] = depth_dist[node] + u.s;
		up[0][u.f] = node;
		for (int i = 1; i < LOGN; i++)
			up[i][u.f] = up[i-1][up[i-1][u.f]];
		dfs(u.f, node);
	}
}

int find(int node, int k) {
	for (int i = 0; i < LOGN; i++) {
		if ((1<<i) & k)
			node = up[i][node];
	}
	return node;
}

int lca(int a, int b) {
	if (depth[b] > depth[a])
		swap(a, b);
	a = find(a, depth[a] - depth[b]);
	if (a == b)
		return a;

	for (int i = LOGN - 1; i >= 0; i--) {
		if (up[i][a] != up[i][b]) {
			a = up[i][a];
			b = up[i][b];
		}
	}
	return up[0][a];
}

int dist(int a, int b) {
	return depth_dist[a] + depth_dist[b] - 2 * depth_dist[lca(a, b)];
}

void Init(int N, vector<int> A, vector<int> B, vector<int> D) {
	graph = vector<vector<pair<int,int>>>(N+1, vector<pair<int,int>>());
	for (int i = 0; i < N-1; i++) {
		graph[A[i]].push_back({B[i], D[i]});
		graph[B[i]].push_back({A[i], D[i]});
	}
	dfs(1, 1);
	decompose(1, true);

	for (int i = 0; i < MAXN; i++)
		ans[i] = 1e15;
}

void add(int node) {
	int now = node;
	while (now != -1) {
		ans[now] = min(ans[now], dist(now, node));
		now = par[now];
	}
}

void remove(int node) {
	while (node != -1) {
		ans[node] = 1e15;
		node = par[node];
	}
}

ll qry(int node) {
	int now = node;
	ll res = 1e15;
	while (now != -1) {
		res = min(res, dist(now, node) + ans[now]);
		now = par[now];
	}
	return res;
}

ll Query(int S, vector<int> X, int T, vector<int> Y) {
	for (auto u : X)
		add(u);

	ll mn = 1e16;
	for (auto u : Y)
		mn = min(mn, qry(u));

	for (auto u : X)
		remove(u);
	return mn;
} 

Compilation message

factories.cpp: In function 'void decompose(int, bool)':
factories.cpp:40:3: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   40 |   par[centro] = -1;
      |   ^~~
      |   __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
factories.cpp:42:3: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   42 |   par[centro] = node;
      |   ^~~
      |   __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
factories.cpp:45:14: error: 'parent' was not declared in this scope
   45 |   if (u.f != parent && !marked[u.f])
      |              ^~~~~~
factories.cpp: In function 'void add(int)':
factories.cpp:107:43: error: no matching function for call to 'min(ll&, int)'
  107 |   ans[now] = min(ans[now], dist(now, node));
      |                                           ^
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 factories.cpp:1:
/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:107:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  107 |   ans[now] = min(ans[now], dist(now, node));
      |                                           ^
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 factories.cpp:1:
/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:107:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  107 |   ans[now] = min(ans[now], dist(now, node));
      |                                           ^
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:1:
/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:107:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  107 |   ans[now] = min(ans[now], dist(now, node));
      |                                           ^
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:1:
/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:107:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  107 |   ans[now] = min(ans[now], dist(now, node));
      |                                           ^
factories.cpp:108:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  108 |   now = par[now];
      |         ^~~
      |         __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
factories.cpp: In function 'void remove(int)':
factories.cpp:115:10: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  115 |   node = par[node];
      |          ^~~
      |          __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
factories.cpp: In function 'll qry(int)':
factories.cpp:124:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  124 |   now = par[now];
      |         ^~~
      |         __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~