Submission #253521

# Submission time Handle Problem Language Result Execution time Memory
253521 2020-07-28T06:43:17 Z kshitij_sodani Cities (BOI16_cities) C++14
0 / 100
6000 ms 19604 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
llo n,k,m;
vector<pair<llo,llo>> adj[100001];
llo dist[1000001];
llo back[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>k>>m;
	llo ans=0;
	vector<llo> dd;
	for(llo i=0;i<k;i++){
		llo aa;
		cin>>aa;
		aa--;
		dd.pb(aa);
	}
	for(llo i=0;i<m;i++){
		llo aa,bb,cc;
		cin>>aa>>bb>>cc;
		aa--;
		bb--;
		adj[aa].pb({bb,cc});
		adj[bb].pb({aa,cc});
		ans+=cc;

	}
	while(true){
		vector<llo> cur;
		cur.pb(dd[0]);
		llo co=0;
		for(llo i=1;i<k;i++){
			for(llo j=0;j<n;j++){
				dist[j]=-1;
				back[j]=-1;
			}
			priority_queue<pair<llo,llo>> ss;
			for(auto j:cur){
				dist[j]=0;
				ss.push({0,j});
			}
			while(ss.size()){
				pair<llo,llo> no=ss.top();
				ss.pop();
				for(auto j:adj[no.b]){
					if(dist[j.a]==-1 or dist[j.a]>dist[no.b]+j.b){
						dist[j.a]=dist[no.b]+j.b;
						back[j.a]=no.b;
						ss.push({-dist[j.a],j.a});
					}
				}
			}
			llo cur2=dd[i];
			co+=dist[dd[i]];
			while(back[cur2]!=-1){
				cur.pb(cur2);
				cur2=back[cur2];
			}
		}
		ans=min(ans,co);




		if(next_permutation(dd.begin(),dd.end())){
			continue;
		}
		break;
	}
	cout<<ans<<endl;





	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Incorrect 2 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 19084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3859 ms 19364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6066 ms 19604 KB Time limit exceeded
2 Halted 0 ms 0 KB -