# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113705 | thebes | Cities (BOI16_cities) | C++14 | 6030 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5+5;
typedef long long ll;
typedef pair<ll,ll> pii;
struct reeee{ll n, m, d;};
ll n, m, k, i, x, y, w, vs[MN][1<<6], ans = 1LL<<60;
vector<pii> adj[MN]; vector<ll> heh;
struct pq{bool operator()(const reeee&i,const reeee&j){return i.d>j.d;}};
priority_queue<reeee,vector<reeee>,pq> q;
int main(){
for(scanf("%lld%lld%lld",&n,&k,&m),i=1;i<=k;i++){
scanf("%lld",&x);
heh.push_back(x);
}
for(i=1;i<=m;i++){
scanf("%lld%lld%lld",&x,&y,&w);
adj[x].push_back({y,w});
adj[y].push_back({x,w});
}
memset(vs,0x3f,sizeof(vs));
for(i=0;i<heh.size();i++)
q.push({heh[i], 1<<i, 0});
while(q.size()){
auto v = q.top(); q.pop();
if(v.m==(1<<k)-1) ans = min(ans, v.d);
if(vs[v.n][v.m]<(1LL<<60)) continue;
vs[v.n][v.m] = v.d;
for(int mm=0;mm<(1<<k);mm++){
if(v.d+vs[v.n][mm]<vs[v.n][v.m|mm]){
q.push({v.n, v.m|mm, v.d+vs[v.n][mm]});
}
}
for(auto w : adj[v.n]){
if(v.d+w.second<vs[w.first][v.m]){
q.push({w.first, v.m, v.d+w.second});
}
}
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |