# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
975896 |
2024-05-06T02:33:35 Z |
Nipphitch |
Cities (BOI16_cities) |
C++11 |
|
1944 ms |
54216 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair <ll,int>
#define f first
#define s second
const int N=1e5+5;
const int K=40;
const ll INF=LLONG_MAX/2;
int n,k,m;
ll dp[K][N];
vector <pii> adj[N];
priority_queue <pii,vector<pii>,greater<pii>> pq;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
fill_n(dp[0],K*N,INF);
cin >> n >> k >> m;
for(int i=0;i<k;i++){
int x;
cin >> x;
dp[(1<<i)][x]=0;
}
for(int i=0;i<m;i++){
int u,v,w;
cin >> u >> v >> w;
adj[u].push_back({v,w});
adj[v].push_back({u,w});
}
for(int mask1=1;mask1<(1<<k);mask1++){
for(int mask2=1;mask2<mask1;mask2++){
if(mask1&mask2){
for(int i=1;i<=n;i++){
dp[mask1][i]=min(dp[mask1][i],dp[mask2][i]+dp[mask1^mask2][i]);
}
}
}
for(int i=1;i<=n;i++) if(dp[mask1][i]!=INF) pq.push({dp[mask1][i],i});
while(!pq.empty()){
auto [d_u,u]=pq.top();
pq.pop();
for(auto [v,w]:adj[u]){
if(dp[mask1][v]>d_u+w) pq.push({dp[mask1][v]=d_u+w,v});
}
}
}
cout << *min_element(dp[(1<<k)-1]+1,dp[(1<<k)-1]+n+1);
}
Compilation message
cities.cpp: In function 'int main()':
cities.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | auto [d_u,u]=pq.top();
| ^
cities.cpp:45:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | for(auto [v,w]:adj[u]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
33880 KB |
Output is correct |
2 |
Correct |
9 ms |
33884 KB |
Output is correct |
3 |
Correct |
7 ms |
33884 KB |
Output is correct |
4 |
Correct |
8 ms |
33884 KB |
Output is correct |
5 |
Correct |
6 ms |
33960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
53448 KB |
Output is correct |
2 |
Correct |
333 ms |
53576 KB |
Output is correct |
3 |
Correct |
170 ms |
43460 KB |
Output is correct |
4 |
Correct |
58 ms |
46536 KB |
Output is correct |
5 |
Correct |
202 ms |
53440 KB |
Output is correct |
6 |
Correct |
55 ms |
46420 KB |
Output is correct |
7 |
Correct |
8 ms |
34140 KB |
Output is correct |
8 |
Correct |
7 ms |
34140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
34140 KB |
Output is correct |
2 |
Correct |
10 ms |
34324 KB |
Output is correct |
3 |
Correct |
8 ms |
34140 KB |
Output is correct |
4 |
Correct |
8 ms |
34200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
842 ms |
54212 KB |
Output is correct |
2 |
Correct |
792 ms |
52976 KB |
Output is correct |
3 |
Correct |
473 ms |
43672 KB |
Output is correct |
4 |
Correct |
416 ms |
50888 KB |
Output is correct |
5 |
Correct |
132 ms |
47288 KB |
Output is correct |
6 |
Correct |
82 ms |
48468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1944 ms |
54216 KB |
Output is correct |
2 |
Correct |
1683 ms |
53076 KB |
Output is correct |
3 |
Correct |
1544 ms |
52152 KB |
Output is correct |
4 |
Correct |
1084 ms |
43460 KB |
Output is correct |
5 |
Correct |
910 ms |
50860 KB |
Output is correct |
6 |
Correct |
221 ms |
47540 KB |
Output is correct |
7 |
Correct |
83 ms |
48980 KB |
Output is correct |