Submission #911527

# Submission time Handle Problem Language Result Execution time Memory
911527 2024-01-19T03:16:40 Z NK_ Cities (BOI16_cities) C++17
14 / 100
2125 ms 53784 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())

template<class T> using V = vector<T>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;
using vl = V<ll>;
using vi = V<int>;
using pl = pair<ll, ll>;
using vpl = V<pl>;



const ll INFL = 2e18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K, M; cin >> N >> K >> M;

	V<vl> dp(N, vl(1 << K, INFL));

	for(int i = 0; i < K; i++) {
		int x; cin >> x; --x;
		dp[x][1 << i] = 0;
	}

	V<vpl> adj(N); for(int i = 0; i < M; i++) {
		int u, v, w; cin >> u >> v >> w; --u, --v;
		adj[u].pb(mp(v, w));
		adj[v].pb(mp(u, w));
	}

	for(int m = 1; m < (1 << K); m++) {
		pq<pl> q; for(int u = 0; u < N; u++) q.push(mp(dp[u][m], u));

		vi vis(N);
		while(sz(q)) {
			int u; ll d; tie(d, u) = q.top(); q.pop();

			if (vis[u]) continue;
			vis[u] = 1;

			for(auto& e : adj[u]) {
				int v, w; tie(v, w) = e;
				if (dp[v][m] > dp[u][m] + w) {
					dp[v][m] = dp[u][m] + w;
					q.push(mp(dp[v][m], v));
				}
			}	
		}

		// cout << m << endl;
		for(int u = 0; u < N; u++) {
			for(int sub = m; sub > 0; sub = (sub - 1) & m) {
				dp[u][m] = min(dp[u][m], dp[u][sub] + dp[u][m ^ sub]);
			}
			// cout << u << " " << dp[u][m] << endl;
		}
		// cout << endl;
	}

	ll ans = INFL;

	for(int u = 0; u < N; u++) ans = min(ans, dp[u][(1 << K) - 1]);

	cout << ans << nl;
	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 639 ms 35776 KB Output is correct
2 Correct 483 ms 34160 KB Output is correct
3 Correct 477 ms 24168 KB Output is correct
4 Correct 53 ms 12976 KB Output is correct
5 Correct 278 ms 32360 KB Output is correct
6 Correct 49 ms 13316 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1247 ms 40616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2125 ms 53784 KB Output isn't correct
2 Halted 0 ms 0 KB -