Submission #624507

#TimeUsernameProblemLanguageResultExecution timeMemory
624507HanksburgerCities (BOI16_cities)C++17
100 / 100
1858 ms42860 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > adj[100005]; priority_queue<pair<long long, long long> > pq; long long dp[32][100005], a[5]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, p; cin >> n >> p >> m; for (long long i=0; i<p; i++) cin >> a[i]; for (long long i=0; i<m; i++) { long long u, v, w; cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } for (long long i=0; i<(1<<p); i++) for (long long j=1; j<=n; j++) dp[i][j]=1e18; for (long long i=0; i<p; i++) dp[1<<i][a[i]]=0; for (long long i=1; i<(1<<p); i++) { for (long long j=0; j<p; j++) if (i&(1<<j)) for (long long k=1; k<=n; k++) dp[i][k]=min(dp[i][k], dp[i^(1<<j)][k]+dp[1<<j][k]); for (long long j=1; j<=n; j++) if (dp[i][j]<1e18) pq.push({-dp[i][j], j}); while (!pq.empty()) { long long d=pq.top().first, u=pq.top().second; pq.pop(); if (dp[i][u]!=-d) continue; for (long long j=0; j<adj[u].size(); j++) { long long v=adj[u][j].first, w=adj[u][j].second; if (dp[i][u]+w<dp[i][v]) { dp[i][v]=dp[i][u]+w; pq.push({-dp[i][v], v}); } } } } long long ans=1e18; for (long long i=1; i<=n; i++) ans=min(ans, dp[(1<<p)-1][i]); cout << ans; return 0; }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:42:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for (long long j=0; j<adj[u].size(); j++)
      |                                 ~^~~~~~~~~~~~~~
#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...