Submission #37264

#TimeUsernameProblemLanguageResultExecution timeMemory
37264szawinisCities (BOI16_cities)C++14
14 / 100
629 ms17580 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int N = 1e5+1;
const ll INF = 1e17+1;

int n, k, m;
vector<int> s;
vector<pair<int,int> > g[N];
ll ans = INF, d[5][N];
priority_queue<pli, vector<pli>, greater<pli> > pq;
int main() {
	scanf("%d %d %d", &n, &k, &m);
	for(int i = 0, v; i < k; i++) {
		scanf("%d", &v);
		s.push_back(v-1);
	}
	for(int i = 0, u, v, w; i < m; i++) {
		scanf("%d %d %d", &u, &v, &w);
		g[u-1].emplace_back(v-1, w);
		g[v-1].emplace_back(u-1, w);
	}
	for(int i = 0; i < k; i++) {
		fill(d[i], d[i]+n, INF);
		d[i][s[i]] = 0;
		pq.emplace(0, s[i]);
		while(!pq.empty()) {
			int u = pq.top().second;
			pq.pop();
			for(auto p: g[u]) if(d[i][u] + p.second < d[i][p.first]) {
				d[i][p.first] = d[i][u] + p.second;
				pq.emplace(d[i][p.first], p.first);
			}
		}
	}
	for(int c = 0; c < n; c++) {
    	ans = min(d[0][c] + d[1][c] + (k == 3 ? d[2][c] : 0), ans);
	}
	printf("%lld", ans);
}

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:14:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &m);
                               ^
cities.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v);
                  ^
cities.cpp:20:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &u, &v, &w);
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...