Submission #1349497

#TimeUsernameProblemLanguageResultExecution timeMemory
1349497vladmart09사이버랜드 (APIO23_cyberland)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <numeric>
#include <array>
#include <iomanip>
#include <stack>
#include <chrono>
#include <climits>
#include <bitset>

using namespace std;

using ll = long long;
using ld = long double;
using vd = vector<ld>;
using vi = vector<ll>;
using vii = vector<vi>;
using viii = vector<vii>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
using vs = vector<string>;

#define vec vector
#define cmax(x, ...) x = max({x, __VA_ARGS__})
#define cmin(x, ...) x = min({x, __VA_ARGS__})
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const ll N = 5e5 + 5, MOD = 1e9 + 7, INF = (ll)1e18, K = 20;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double solve(ll n, ll m, ll k, ll h, vi x, vi y, vi c, vi arr) {
	vector<vpi> g(n);
	cmin(k, 70ll);

	for (ll i = 0; i < m; i++) {
		g[x[i]].push_back({ y[i], c[i] });
		g[y[i]].push_back({ x[i], c[i] });
	}

	vb reach(n, false);

	auto check = [&](auto&& check, ll v, ll p = -1) -> void {
		reach[v] = true;
		if (v == h) return;

		for (auto& [x, y] : g[v]) {
			if (x == p) continue;

			check(check, x, v);
		}
	};

	check(check, 0);
	if (!reach[h]) return -1;
	vd dp(n, INF); for (ll i = 0; i < n; i++) {
		if (reach[i] && (i == 0 || arr[i] == 0)) dp[i] = 0;
	}
	ld ans = INF;

	for (ll i = 0; i <= k; i++) {
		priority_queue<pair<ld, ll>, vector<pair<ld, ll>>, greater<>> pq;

		for (ll j = 0; j < n; j++) {
			if (dp[j] != INF) pq.push({dp[j], j});
		}

		while (!pq.empty()) {
			auto [w, v] = pq.top(); pq.pop();

			if (w > dp[v]) continue;
			dp[v] = w;
			if (v == h) continue;

			for (auto& [x, y] : g[v]) {
				if (w + y > dp[x]) continue;

				pq.push({ w + y, x});
			}
		}

		cmin(ans, dp[h]);

		vd ndp(n, INF);

		for (ll j = 0; j < n; j++) {
			if (dp[j] == INF || j == h) continue;

			for (auto& [x, y] : g[j]) {
				if (arr[x] != 2) continue;
				cmin(ndp[x], (dp[j] + y) / 2);
			}
		}

		for (ll j = 0; j < n; j++) cmin(dp[j], ndp[j]);
	}

	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long tt = 1;
	//cin >> tt;

	while (tt--) {
		solve(4, 4, 30, 3, { 0, 0, 1, 2 }, { 1, 2, 3, 3 }, { 5, 4, 2, 4 }, { 1, 0, 2, 1 });
		cout << '\n';
	}

	return 0;
}

/*


Можно начинать от 0 а также городов которые обнуляют. А вот что делать с делением хзшка




































Какие темы повторить:
1) мст
2) 2сат
3) точки артикуляции
4) ксор базис
5) эйлеровый цикл, путь
6) кмп
7) конвекс хулл
8) вафельное дерево
9) суфиксный массив
10) суффиксный автомат
11) ним

*/

Compilation message (stderr)

/usr/bin/ld: /tmp/ccXXRKzm.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccvzz8XY.o:cyberland.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccXXRKzm.o: in function `main':
grader.cpp:(.text.startup+0x700): undefined reference to `solve(int, int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status