Submission #253856

# Submission time Handle Problem Language Result Execution time Memory
253856 2020-07-28T23:07:03 Z super_j6 Cities (BOI16_cities) C++14
15 / 100
6000 ms 67560 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 = 100000;
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{
		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 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Incorrect 3 ms 4992 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6010 ms 64056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 413 ms 13048 KB Output is correct
2 Correct 443 ms 13304 KB Output is correct
3 Correct 208 ms 12920 KB Output is correct
4 Correct 139 ms 7288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6048 ms 65720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6074 ms 67560 KB Time limit exceeded
2 Halted 0 ms 0 KB -