Submission #276539

# Submission time Handle Problem Language Result Execution time Memory
276539 2020-08-20T13:38:18 Z islingr Olympic Bus (JOI20_ho_t4) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x...) begin(x), end(x)

using ll = long long;

template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

const int N = 1 << 9, M = 1 << 16;
const ll inf = 1e18;

int n;
ll d[N][N];
int a[M], b[M], w[M], c[M];
vector<int> g[N];
bool onPath[M], vis[N];

bool dfs(int u, int t) {
	if (u == t) return true;
	vis[u] = true;
	for (int e : g[u]) {
		assert(a[e] == u);
		int v = b[e];
		assert(d[u][t] <= w[e] + d[v][t]);
		if (!vis[v] && w[e] + d[v][t] == d[u][t] && dfs(v, t))
			return onPath[e] = true;
	}
	return false;
}


using pq_t = __gnu_pbds::priority_queue<pair<ll, int>, greater<>>;
pq_t::point_iterator it[N];

ll dij(int s, int t) {
	pq_t pq;
	rep(u, 0, n) if (u != s) it[u] = pq.push({inf, u});
	it[s] = pq.push({0, s});

	while (!pq.empty()) {
		int u; ll dist;
		tie(u, dist) = pq.top();
		pq.pop(); it[u] = nullptr;
		if (u == t) return dist;
		for (int e : g[u]) {
			int v = b[e];
			if (it[v]) {
				dist += w[e];
				if (dist < it[v]->first)
					pq.modify(it[v], {dist, v});
				dist -= w[e];
			}
		}
	}
	return inf;
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);

	int m; cin >> n >> m;
	rep(u, 0, n) rep(v, 0, n) d[u][v] = inf;
	rep(u, 0, n) d[u][u] = 0;
	rep(e, 0, m) {
		cin >> a[e] >> b[e] >> w[e] >> c[e], --a[e], --b[e];
		ckmin(d[a[e]][b[e]], ll(w[e]));
		g[a[e]].push_back(e);
	}

	rep(w, 0, n)
		rep(u, 0, n)
			rep(v, 0, n)
				ckmin(d[u][v], d[u][w] + d[w][v]);

	int s = 0, t = n - 1;
	fill(vis, vis + n, 0); dfs(s, t);
	fill(vis, vis + n, 0); dfs(t, s);

	ll ans = d[s][t] + d[t][s];
	rep(e, 0, m) {
		if (!onPath[e]) {
			ll to = min(d[s][t], d[s][b[e]] + w[e] + d[a[e]][t]);
			ll fr = min(d[t][s], d[t][b[e]] + w[e] + d[a[e]][s]);
			ckmin(ans, c[e] + to + fr);
		} else {
			g[a[e]].erase(find(all(g[a[e]]), e));
			swap(a[e], b[e]);
			g[a[e]].push_back(e);
			ckmin(ans, c[e] + dij(0, n - 1) + dij(n - 1, 0));
			g[a[e]].pop_back();
			swap(a[e], b[e]);
			g[a[e]].push_back(e);
		}
	}

	cout << (ans < inf ? ans : -1);
}

Compilation message

ho_t4.cpp: In function 'll dij(int, int)':
ho_t4.cpp:51:12: error: could not convert 'it[v]' from '__gnu_pbds::priority_queue<std::pair<long long int, int>, std::greater<void> >::point_iterator' {aka '__gnu_pbds::detail::left_child_next_sibling_heap_node_point_const_iterator_<__gnu_pbds::detail::left_child_next_sibling_heap_node_<std::pair<long long int, int>, __gnu_pbds::null_type, std::allocator<char> >, std::allocator<char> >'} to 'bool'
   51 |    if (it[v]) {
      |        ~~~~^
      |            |
      |            __gnu_pbds::priority_queue<std::pair<long long int, int>, std::greater<void> >::point_iterator {aka __gnu_pbds::detail::left_child_next_sibling_heap_node_point_const_iterator_<__gnu_pbds::detail::left_child_next_sibling_heap_node_<std::pair<long long int, int>, __gnu_pbds::null_type, std::allocator<char> >, std::allocator<char> >}