# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447004 |
2021-07-24T08:11:04 Z |
prvocislo |
Cities (BOI16_cities) |
C++17 |
|
2642 ms |
43344 KB |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll inf = 1e18 + 5;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, m;
cin >> n >> k >> m;
vector<int> im(k);
for (int i = 0; i < k; i++)
cin >> im[i], im[i]--;
vector<vector<pair<int, int> > > g(n);
for (int i = 0, a, b, c; i < m; i++)
cin >> a >> b >> c, g[--a].push_back({--b, c}), g[b].push_back({a, c});
vector<vector<ll> > dp((1 << k), vector<ll>(n, inf));
dp[0].assign(n, 0);
priority_queue<pair<ll, int> > pq;
for (int m = 1; m < (1 << k); m++)
{
for (int i = 0; i < n; i++)
{
int id = find(im.begin(), im.end(), i) - im.begin();
if (m & (1 << id)) dp[m][i] = dp[m^(1 << id)][i];
else for (int s = m; s; s = (s-1)&m)
dp[m][i] = min(dp[m][i], dp[s][i] + dp[m^s][i]);
pq.push({-dp[m][i], i});
}
vector<bool> vis(n, false);
while (!pq.empty())
{
ll d = -pq.top().first; int u = pq.top().second;
pq.pop();
if (vis[u]) continue;
vis[u] = true;
for (const pair<int, int> &i : g[u])
{
if (!vis[i.first] && dp[m][i.first] > d + i.second)
{
dp[m][i.first] = d + i.second;
pq.push({-dp[m][i.first], i.first});
}
}
}
}
cout << (*min_element(dp[(1<<k)-1].begin(), dp[(1<<k)-1].end())) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
20812 KB |
Output is correct |
2 |
Correct |
640 ms |
20596 KB |
Output is correct |
3 |
Correct |
533 ms |
15924 KB |
Output is correct |
4 |
Correct |
90 ms |
5828 KB |
Output is correct |
5 |
Correct |
331 ms |
17868 KB |
Output is correct |
6 |
Correct |
97 ms |
5800 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
624 KB |
Output is correct |
2 |
Correct |
8 ms |
588 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1235 ms |
27076 KB |
Output is correct |
2 |
Correct |
1328 ms |
26896 KB |
Output is correct |
3 |
Correct |
948 ms |
22204 KB |
Output is correct |
4 |
Correct |
732 ms |
16760 KB |
Output is correct |
5 |
Correct |
198 ms |
8436 KB |
Output is correct |
6 |
Correct |
114 ms |
7524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2642 ms |
39576 KB |
Output is correct |
2 |
Correct |
2584 ms |
43344 KB |
Output is correct |
3 |
Correct |
2384 ms |
42928 KB |
Output is correct |
4 |
Correct |
1699 ms |
36024 KB |
Output is correct |
5 |
Correct |
1310 ms |
26540 KB |
Output is correct |
6 |
Correct |
284 ms |
12624 KB |
Output is correct |
7 |
Correct |
139 ms |
10196 KB |
Output is correct |