제출 #37263

#제출 시각아이디문제언어결과실행 시간메모리
37263szawinisCities (BOI16_cities)C++14
0 / 100
516 ms16116 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++) { for(int i1 = 0; i1 < k; i1++) for(int i2 = 0; i2 < k; i2++) { if(i1 != i2 && d[i1][c] + d[i2][c] == d[i1][s[i2]]) { ans = min(d[0][c] + d[1][c] + (k == 3 ? d[2][c] : 0), ans); break; } } } printf("%lld", ans); }

컴파일 시 표준 에러 (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...