Submission #879456

#TimeUsernameProblemLanguageResultExecution timeMemory
879456KN200711Cities (BOI16_cities)C++14
14 / 100
328 ms27556 KiB
# include <bits/stdc++.h> # define ll long long # define fi first # define se second using namespace std; vector< pair<int, ll> > edge[100001]; ll dist[100001], mn[5][100001]; bool vis[100001]; int main() { int N, K, M; scanf("%d %d %d", &N, &K, &M); vector<int> ipr(K); for(int i=0;i<K;i++) { scanf("%d", &ipr[i]); } for(int i=0;i<M;i++) { int a, b; ll c; scanf("%d %d %lld", &a, &b, &c); edge[a].push_back(make_pair(b, c)); edge[b].push_back(make_pair(a, c)); } for(int i=0;i<K;i++) { priority_queue< pair<ll, int> > PQ; PQ.push(make_pair(0ll, ipr[i])); for(int c=1;c<=N;c++) vis[c] = 0; while(!PQ.empty()) { ll a = PQ.top().fi; int b = PQ.top().se; PQ.pop(); if(vis[b]) continue; vis[b] = 1; mn[i][b] = -a; dist[b] -= a; for(int c=0;c<edge[b].size();c++) { if(!vis[edge[b][c].fi]) PQ.push(make_pair(a - 1ll * edge[b][c].se, edge[b][c].fi)); } } } ll ans = 1e18; for(int d=1;d<=N;d++) { ans = min(ans, dist[d]); } if(K == 4) { for(int i=1;i<=N;i++) { for(int c=0;c<4;c++) { ll as = 0ll, v= 1e18; for(int d=0;d<4;d++) { if(c == d) continue; v = min(v, mn[d][ipr[c]]); as += mn[d][i]; } as += v; ans = min(ans, as); } } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for(int c=0;c<edge[b].size();c++) {
      |                ~^~~~~~~~~~~~~~~
cities.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d %d %d", &N, &K, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d", &ipr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
cities.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d %d %lld", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...