제출 #467880

#제출 시각아이디문제언어결과실행 시간메모리
467880shanem_1401Cities (BOI16_cities)C++14
15 / 100
246 ms262148 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef long long ll; int n, m, k; int main() { scanf("%d %d %d",& n,& k,& m); vector<int>penting; for(int i=0; i<k; i++) { int temp; scanf("%d",& temp); penting.push_back(temp); } vector<pii>v[n+2]; for(int i=0; i<m; i++) { int from, to, cost; scanf("%d %d %d",& from,& to,& cost); v[from].pb(mp(cost, to)); v[to].pb(mp(cost, from)); } ll dist[n+2][n+2]; for(int i=1; i<=n; i++) fill(dist[i]+1, dist[i]+n+1, 2e18); if(k==2) { penting.resize(3, penting[0]); k=3; } for(int i=1; i<=n; i++) { priority_queue<pair<ll, int> >pq; pq.push(mp(0, i)); dist[i][i]=0; while(!pq.empty()) { ll cost=-pq.top().fi; int from=pq.top().se; pq.pop(); if(dist[i][from]!=cost) continue; for(int j=0; j<v[from].size(); j++) { int to=v[from][j].se; ll price=v[from][j].fi+cost; if(dist[i][to]>price) { dist[i][to]=price; pq.push(mp(-price, to)); } } } } ll mini=2e18; if(k==3) { for(int i=1; i<=n; i++) { ll total=0; for(int j=0; j<k; j++) total+=dist[penting[j]][i]; mini=min(mini, total); } } else { for(int x=1; x<=n; x++) { for(int y=1; y<=n; y++) { ll total=dist[x][y]; for(int j=0; j<k; j++) total+=min(dist[penting[j]][x], dist[penting[j]][y]); mini=min(mini, total); } } } printf("%lld\n", mini); } /* 6 4 5 1 2 4 5 1 3 1 2 3 2 4 6 1 5 6 2 3 6 3 */

컴파일 시 표준 에러 (stderr) 메시지

cities.cpp: In function 'int main()':
cities.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int j=0; j<v[from].size(); j++)
      |                 ~^~~~~~~~~~~~~~~
cities.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d %d %d",& n,& k,& m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d",& temp);
      |   ~~~~~^~~~~~~~~~~~~
cities.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d %d %d",& from,& to,& cost);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...