Submission #446996

# Submission time Handle Problem Language Result Execution time Memory
446996 2021-07-24T08:01:34 Z prvocislo Cities (BOI16_cities) C++17
74 / 100
6000 ms 41636 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())
        {
            ll d = pq.begin()->first; int 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 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 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1483 ms 22776 KB Output is correct
2 Correct 1488 ms 25184 KB Output is correct
3 Correct 797 ms 20404 KB Output is correct
4 Correct 99 ms 8392 KB Output is correct
5 Correct 744 ms 22248 KB Output is correct
6 Correct 80 ms 8260 KB Output is correct
7 Correct 6 ms 452 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 616 KB Output is correct
2 Correct 11 ms 588 KB Output is correct
3 Correct 7 ms 460 KB Output is correct
4 Correct 7 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2785 ms 29220 KB Output is correct
2 Correct 3229 ms 31464 KB Output is correct
3 Correct 1738 ms 26872 KB Output is correct
4 Correct 1488 ms 20552 KB Output is correct
5 Correct 321 ms 10692 KB Output is correct
6 Correct 112 ms 9944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6086 ms 41636 KB Time limit exceeded
2 Halted 0 ms 0 KB -