제출 #37327

#제출 시각아이디문제언어결과실행 시간메모리
37327szawinisCities (BOI16_cities)C++14
0 / 100
2523 ms41116 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], d2[1 << 5][N], res[1 << 5]; 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 mask = 0; mask < 1 << k; mask++) { for(int v = 0; v < n; v++) d2[mask][v] = INF; res[mask] = INF; } for(int i = 0; i < k; i++) d2[1 << i][s[i]] = res[1 << i] = 0; for(int mask = 1; mask < (1 << k)-1; mask++) {// chec klimits for(int v = 0; v < n; v++) if(!d2[mask][v]) pq.emplace(0, v); while(!pq.empty()) { int u = pq.top().second; pq.pop(); for(auto p: g[u]) if(d2[mask][u] + p.second < d2[mask][p.first]) { d2[mask][p.first] = d2[mask][u] + p.second; pq.emplace(d2[mask][p.first], p.first); } } for(int i = 0; i < k; i++) if(!(mask >> i & 1)) { int new_mask = mask | 1 << i; for(int v = 0; v < n; v++) { if(!d2[mask][v] || d2[mask][v] + d[i][v] == d2[mask][s[i]]) d2[new_mask][v] = 0; } res[new_mask] = min(res[mask] + d2[mask][s[i]], res[new_mask]); } } printf("%lld", res[(1 << k) - 1]); }

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