# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
361709 |
2021-01-31T10:41:16 Z |
cpp219 |
Cities (BOI16_cities) |
C++14 |
|
3067 ms |
47112 KB |
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 69;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<LL> g[N];
ll n,k,m,a[N],c,x,y,d[35][N],ans = inf;
ll b[N];
bool chkmask(ll mask,ll now){
ll new_mask = mask | now;
return new_mask == mask;
}
struct Node{
ll val,cur;
};
bool operator < (Node x,Node y){
return x.val < y.val||(x.val == y.val && x.cur < y.cur);
}
void Dij(){
for (ll i = 0;i < 33;i++)
for (ll j = 1;j <= n;j++) d[i][j] = inf;
for (ll i = 1;i <= k;i++) d[(1 << (i - 1))][a[i]] = 0;
for (ll mask = 1;mask < (1 << k);mask++){
for (ll m1 = 1;m1 <= mask;m1++){
if (!chkmask(mask,m1)) continue;
ll m2 = mask ^ m1;
if (m2 > m1) continue;
for (ll i = 1;i <= n;i++) d[mask][i] = min(d[mask][i],d[m1][i] + d[m2][i]);
}
priority_queue<LL,vector<LL>,greater<LL>> pq;
for (ll i = 1;i <= n;i++) if (d[mask][i] != inf) pq.push({d[mask][i],i});
while(!pq.empty()){
LL t = pq.top(); pq.pop();
ll u = t.sc;
for (auto i : g[u]){
ll v = i.fs,L = i.sc;
if (d[mask][v] > d[mask][u] + L){
d[mask][v] = d[mask][u] + L;
pq.push({d[mask][v],v});
}
}
}
}
for (ll i = 1;i <= n;i++) ans = min(ans,d[(1 << k) - 1][i]);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>k>>m;
for (ll i = 1;i <= k;i++) cin>>a[i];
while(m--){
cin>>x>>y>>c;
g[x].push_back({y,c}); g[y].push_back({x,c});
}
Dij(); cout<<ans;
}
Compilation message
cities.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
cities.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
cities.cpp: In function 'int main()':
cities.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
63 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2924 KB |
Output is correct |
2 |
Correct |
2 ms |
2924 KB |
Output is correct |
3 |
Correct |
2 ms |
2944 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
45264 KB |
Output is correct |
2 |
Correct |
724 ms |
44764 KB |
Output is correct |
3 |
Correct |
401 ms |
37532 KB |
Output is correct |
4 |
Correct |
83 ms |
12196 KB |
Output is correct |
5 |
Correct |
354 ms |
43180 KB |
Output is correct |
6 |
Correct |
74 ms |
12196 KB |
Output is correct |
7 |
Correct |
5 ms |
3308 KB |
Output is correct |
8 |
Correct |
4 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3308 KB |
Output is correct |
2 |
Correct |
7 ms |
3308 KB |
Output is correct |
3 |
Correct |
6 ms |
3180 KB |
Output is correct |
4 |
Correct |
5 ms |
3180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1503 ms |
45488 KB |
Output is correct |
2 |
Correct |
1433 ms |
44856 KB |
Output is correct |
3 |
Correct |
891 ms |
37680 KB |
Output is correct |
4 |
Correct |
803 ms |
29988 KB |
Output is correct |
5 |
Correct |
210 ms |
15524 KB |
Output is correct |
6 |
Correct |
102 ms |
14572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3003 ms |
45724 KB |
Output is correct |
2 |
Correct |
3067 ms |
47112 KB |
Output is correct |
3 |
Correct |
2931 ms |
46740 KB |
Output is correct |
4 |
Correct |
1906 ms |
39276 KB |
Output is correct |
5 |
Correct |
1564 ms |
31460 KB |
Output is correct |
6 |
Correct |
338 ms |
17020 KB |
Output is correct |
7 |
Correct |
123 ms |
15980 KB |
Output is correct |