Submission #253855

# Submission time Handle Problem Language Result Execution time Memory
253855 2020-07-28T23:05:41 Z super_j6 Cities (BOI16_cities) C++14
0 / 100
310 ms 8444 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

ll inf = 0x3f3f3f3f3f3f3f3f;
const int mxn = 1000;
int n, m, k;
int a[mxn];
vector<ll> d[mxn];
vector<pi> g[mxn];
set<pi> pq;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> m;
	
	for(int i = 0; i < k; i++){
		cin >> a[i];
		a[i]--;
	}

	for(int i = 0; i < m; i++){
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	
	for(int s = 0; s < n; s++){
		if(k > 3 || find(a, a + k, s)){
			d[s].assign(n, inf);
			d[s][s] = 0;
			pq.insert({0, s});
			while(!pq.empty()){
				int c = pq.begin()->s;
				pq.erase(pq.begin());
				for(pi i : g[c]){
					if(d[s][c] + i.s < d[s][i.f]){
						pq.erase({d[s][c], i.f});
						pq.insert({d[s][i.f] = d[s][c] + i.s, i.f});
					}
				}
			}
		}
	}
	
	ll ret = inf;
	if(k <= 3){
		for(int i = 0; i < n; i++){
			ll cur = 0;
			for(int j = 0; j < k; j++){
				cur += d[a[j]][i];
			}
			ret = min(ret, cur);
		}
	}else{
		ll ret = inf;
		for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
		for(int l = 0; l < (1 << k); l++){
			ll cur = d[i][j];
			for(int p = 0; p < k; p++){
				cur += d[a[p]][((l >> p) & 1) ? i : j];
			}
			ret = min(ret, cur);
		}
	}
	
	cout << ret << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 8444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -