# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
446987 |
2021-07-24T07:48:29 Z |
prvocislo |
Cities (BOI16_cities) |
C++17 |
|
6000 ms |
44364 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);
for (int m = 1; m < (1 << k); m++)
{
set<pair<ll, int> > pq;
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.insert({dp[m][i], i});
}
vector<bool> vis(n, false);
while (!pq.empty())
{
int d = pq.begin()->first, u = pq.begin()->second;
pq.erase(pq.begin());
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)
{
pq.erase({dp[m][i.first], i.first});
dp[m][i.first] = d + i.second;
pq.insert({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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1603 ms |
25468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3022 ms |
31808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6077 ms |
44364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |