Submission #682618

# Submission time Handle Problem Language Result Execution time Memory
682618 2023-01-16T15:31:52 Z Ronin13 Cities (BOI16_cities) C++14
74 / 100
6000 ms 48292 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax =1e5 + 1;

const ll linf = 1e18 + 1;
ll d[nmax][32];
vector <vector <pll> > g(nmax);

int main(){
    int n; cin >> n;
    int k; cin >> k;
    int m; cin >> m;
    int imp[k + 1];
    for(int i= 1; i <= n; i++)
        for(int j = 0; j < 32; j++)
            d[i][j] = linf;
    for(int i = 1; i <= k; i++) {
        cin >> imp[i];
    }
    for(int i= 1; i <= m; i++){
        int u, v, len;
        cin >> u >> v >> len;
        g[u].epb(v, len);
        g[v].epb(u, len);
    }
    for(int i = 0; i < k; i++){
        d[imp[i + 1]][(1 << i)] = 0;
    }
    for(int mask = 1; mask < (1 << k); mask++){
        for(int submask = 1; submask < mask; submask++){
            if((mask | submask) != mask) continue;
            for(int j = 1; j <= n; j++)
                d[j][mask] = min(d[j][mask], d[j][submask] + d[j][mask ^ submask]);
        }
        set <pll> st;
        for(int i = 1; i <= n; ++i){
            if(d[i][mask] != linf)
                st.insert({d[i][mask], i});
        }
        while(!st.empty()){
            int v = st.begin()->s;
            st.erase(st.begin());
            for(auto x : g[v]){
                int to = x.f;
                ll len = x.s;
                if(d[v][mask] + len < d[to][mask]){
                    st.erase({d[to][mask], to});
                    d[to][mask] = d[v][mask] + len;
                    st.insert({d[to][mask], to});
                }
            }
        }
    }
    cout << d[imp[1]][(1 << k) - 1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1347 ms 48196 KB Output is correct
2 Correct 1360 ms 47436 KB Output is correct
3 Correct 533 ms 41164 KB Output is correct
4 Correct 185 ms 15344 KB Output is correct
5 Correct 602 ms 48116 KB Output is correct
6 Correct 191 ms 15168 KB Output is correct
7 Correct 6 ms 3028 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3064 KB Output is correct
2 Correct 14 ms 3068 KB Output is correct
3 Correct 8 ms 2936 KB Output is correct
4 Correct 8 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2734 ms 48292 KB Output is correct
2 Correct 2769 ms 47300 KB Output is correct
3 Correct 1342 ms 41268 KB Output is correct
4 Correct 1406 ms 32128 KB Output is correct
5 Correct 419 ms 18012 KB Output is correct
6 Correct 196 ms 17404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6039 ms 48236 KB Time limit exceeded
2 Halted 0 ms 0 KB -