# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113716 | 2019-05-28T02:14:35 Z | thebes | Cities (BOI16_cities) | C++14 | 5440 ms | 204372 KB |
#include <bits/stdc++.h> using namespace std; const int MN = 1e5+5; typedef long long ll; typedef pair<ll,ll> pii; struct reeee{int n, m; ll d;}; bool ww[MN][1<<6]; 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){ printf("%lld\n",v.d); return 0; } if(ww[v.n][v.m]) continue; vs[v.n][v.m] = v.d; ww[v.n][v.m] = 1; for(int mm=(1<<k);mm;mm=((mm-1)&(~v.m))){ if(v.d+vs[v.n][mm]<vs[v.n][v.m|mm]){ vs[v.n][v.m|mm]=v.d+vs[v.n][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]){ vs[w.first][v.m]=v.d+w.second; q.push({w.first, v.m, v.d+w.second}); } } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 52728 KB | Output is correct |
2 | Correct | 40 ms | 52864 KB | Output is correct |
3 | Correct | 42 ms | 52856 KB | Output is correct |
4 | Correct | 44 ms | 52860 KB | Output is correct |
5 | Correct | 40 ms | 52920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 657 ms | 86032 KB | Output is correct |
2 | Correct | 639 ms | 76828 KB | Output is correct |
3 | Correct | 192 ms | 65548 KB | Output is correct |
4 | Correct | 139 ms | 62196 KB | Output is correct |
5 | Correct | 339 ms | 73656 KB | Output is correct |
6 | Correct | 122 ms | 62028 KB | Output is correct |
7 | Correct | 42 ms | 53112 KB | Output is correct |
8 | Correct | 41 ms | 52940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 53600 KB | Output is correct |
2 | Correct | 46 ms | 53400 KB | Output is correct |
3 | Correct | 42 ms | 53112 KB | Output is correct |
4 | Correct | 43 ms | 53368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2067 ms | 102300 KB | Output is correct |
2 | Correct | 1681 ms | 101444 KB | Output is correct |
3 | Correct | 1140 ms | 80864 KB | Output is correct |
4 | Correct | 1120 ms | 99404 KB | Output is correct |
5 | Correct | 236 ms | 70608 KB | Output is correct |
6 | Correct | 140 ms | 64596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5440 ms | 200960 KB | Output is correct |
2 | Correct | 5423 ms | 200960 KB | Output is correct |
3 | Correct | 5168 ms | 204372 KB | Output is correct |
4 | Correct | 2439 ms | 132332 KB | Output is correct |
5 | Correct | 3279 ms | 136344 KB | Output is correct |
6 | Correct | 585 ms | 82876 KB | Output is correct |
7 | Correct | 184 ms | 69632 KB | Output is correct |