# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
75743 |
2018-09-11T01:13:58 Z |
polyfish |
Cities (BOI16_cities) |
C++14 |
|
4326 ms |
81396 KB |
//pantyhose(black) + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
typedef pair<int64_t, int> pairInts;
const int MAX_N = 100002;
const int MAX_K = 5;
const int64_t INF = 1e18;
int n, m, k, important_city[MAX_K];
int64_t f[1<<MAX_K][MAX_N];
vector<pairInts> g[MAX_N];
priority_queue<pairInts, vector<pairInts>, greater<pairInts> > pq;
void enter() {
cin >> n >> k >> m;
for (int i=0; i<k; ++i) {
cin >> important_city[i];
}
for (int i=1; i<=m; ++i) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back(make_pair(w, v));
g[v].push_back(make_pair(w, u));
}
}
void dijkstra(int x) {
for (int i=1; i<=n; ++i)
pq.push(make_pair(f[x][i], i));
while (pq.size()) {
int u = pq.top().second;
int64_t du = pq.top().first;
pq.pop();
if (du!=f[x][u])
continue;
for (int i=0; i<g[u].size(); ++i) {
int v = g[u][i].second, w = g[u][i].first;
if (f[x][v]>f[x][u]+w) {
pq.push(make_pair(f[x][v] = f[x][u] + w, v));
}
}
}
}
void dp() {
for (int x=0; x<(1<<k); ++x)
for (int i=1; i<=n; ++i)
f[x][i] = INF;
for (int i=0; i<k; ++i)
f[1<<i][important_city[i]] = 0;
for (int x=0; x<(1<<k); ++x) {
for (int u=1; u<=n; ++u) {
for (int i=0; i<g[u].size(); ++i) {
int v = g[u][i].second, w = g[u][i].first;
for (int x2 = x; x2>0; x2 = (x2 - 1) & x) {
f[x][u] = min(f[x][u], f[x2][v] + f[x^x2][u] + w);
}
}
}
dijkstra(x);
}
int64_t res = INF;
for (int i=1; i<=n; ++i)
res = min(res, f[(1<<k)-1][i]);
cout << res;
}
int main() {
#ifdef OFFLINE_JUDGE
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
enter();
dp();
}
Compilation message
cities.cpp: In function 'void dijkstra(int)':
cities.cpp:45:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<g[u].size(); ++i) {
~^~~~~~~~~~~~
cities.cpp: In function 'void dp()':
cities.cpp:62:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<g[u].size(); ++i) {
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2684 KB |
Output is correct |
3 |
Correct |
4 ms |
2848 KB |
Output is correct |
4 |
Correct |
5 ms |
2928 KB |
Output is correct |
5 |
Correct |
5 ms |
3008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
878 ms |
28080 KB |
Output is correct |
2 |
Correct |
857 ms |
31336 KB |
Output is correct |
3 |
Correct |
453 ms |
31336 KB |
Output is correct |
4 |
Correct |
124 ms |
31336 KB |
Output is correct |
5 |
Correct |
449 ms |
39044 KB |
Output is correct |
6 |
Correct |
107 ms |
39044 KB |
Output is correct |
7 |
Correct |
8 ms |
39044 KB |
Output is correct |
8 |
Correct |
6 ms |
39044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
39044 KB |
Output is correct |
2 |
Correct |
13 ms |
39044 KB |
Output is correct |
3 |
Correct |
12 ms |
39044 KB |
Output is correct |
4 |
Correct |
9 ms |
39044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1660 ms |
56332 KB |
Output is correct |
2 |
Correct |
1769 ms |
56332 KB |
Output is correct |
3 |
Correct |
1231 ms |
56332 KB |
Output is correct |
4 |
Correct |
1051 ms |
56332 KB |
Output is correct |
5 |
Correct |
371 ms |
56332 KB |
Output is correct |
6 |
Correct |
191 ms |
56332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4326 ms |
73696 KB |
Output is correct |
2 |
Correct |
3925 ms |
78076 KB |
Output is correct |
3 |
Correct |
3549 ms |
81396 KB |
Output is correct |
4 |
Correct |
2439 ms |
81396 KB |
Output is correct |
5 |
Correct |
2147 ms |
81396 KB |
Output is correct |
6 |
Correct |
775 ms |
81396 KB |
Output is correct |
7 |
Correct |
356 ms |
81396 KB |
Output is correct |