Submission #113711

# Submission time Handle Problem Language Result Execution time Memory
113711 2019-05-28T02:03:20 Z thebes Cities (BOI16_cities) C++14
74 / 100
6000 ms 84784 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int MN = 1e5+5;
typedef long long ll;
typedef pair<ll,ll> pii;
struct reeee{int n, m;};

bool ww[MN][1<<6];
ll n, m, k, i, x, y, w, vs[MN][1<<6], ans = 1LL<<60;
vector<pii> adj[MN]; vector<ll> heh;
queue<reeee> idk;

int main(){
    for(scanf("%lld%lld%lld",&n,&k,&m),i=1;i<=k;i++){
        scanf("%lld",&x);
        heh.push_back(x);
    }
    for(i=1;i<=m;i++){
        scanf("%lld%lld%lld",&x,&y,&w);
        adj[x].push_back({y,w});
        adj[y].push_back({x,w});
    }
    memset(vs,0x3f,sizeof(vs));
    for(i=0;i<heh.size();i++)
        idk.push({heh[i], 1<<i}), ww[heh[i]][1<<i]=1, vs[heh[i]][1<<i]=0;
    while(idk.size()){
        reeee v = idk.front(); idk.pop();
        if(v.m==(1<<k)-1) ans = min(ans, vs[v.n][v.m]);
        if(!ww[v.n][v.m]) continue;
        ww[v.n][v.m] = 0;
        for(int mm=0;mm<(1<<k);mm++){
            if(vs[v.n][v.m]+vs[v.n][mm]<vs[v.n][v.m|mm]){
                vs[v.n][v.m|mm] = vs[v.n][v.m]+vs[v.n][mm];
                if(!ww[v.n][v.m|mm]) idk.push({v.n, v.m|mm});
                ww[v.n][v.m|mm] = 1;
            }
        }
        for(auto w : adj[v.n]){
            if(vs[v.n][v.m]+w.second<vs[w.first][v.m]){
                vs[w.first][v.m] = vs[v.n][v.m]+w.second;
                if(!ww[w.first][v.m]) idk.push({w.first, v.m});
                ww[w.first][v.m] = 1;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<heh.size();i++)
             ~^~~~~~~~~~~
cities.cpp:29:32: warning: narrowing conversion of 'heh.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' to 'int' inside { } [-Wnarrowing]
         idk.push({heh[i], 1<<i}), ww[heh[i]][1<<i]=1, vs[heh[i]][1<<i]=0;
                                ^
cities.cpp:45:51: warning: narrowing conversion of 'w.std::pair<long long int, long long int>::first' from 'long long int' to 'int' inside { } [-Wnarrowing]
                 if(!ww[w.first][v.m]) idk.push({w.first, v.m});
                                                 ~~^~~~~
cities.cpp:18:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%lld%lld%lld",&n,&k,&m),i=1;i<=k;i++){
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
cities.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
cities.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&x,&y,&w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 52736 KB Output is correct
2 Correct 39 ms 52792 KB Output is correct
3 Correct 40 ms 52856 KB Output is correct
4 Correct 40 ms 52728 KB Output is correct
5 Correct 40 ms 52728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1417 ms 72472 KB Output is correct
2 Correct 1261 ms 71668 KB Output is correct
3 Correct 281 ms 64380 KB Output is correct
4 Correct 169 ms 61568 KB Output is correct
5 Correct 545 ms 70648 KB Output is correct
6 Correct 140 ms 61532 KB Output is correct
7 Correct 42 ms 52984 KB Output is correct
8 Correct 43 ms 52984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 53048 KB Output is correct
2 Correct 45 ms 52940 KB Output is correct
3 Correct 43 ms 52860 KB Output is correct
4 Correct 44 ms 52988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3355 ms 76124 KB Output is correct
2 Correct 2837 ms 76128 KB Output is correct
3 Correct 515 ms 64420 KB Output is correct
4 Correct 1932 ms 70876 KB Output is correct
5 Correct 373 ms 63448 KB Output is correct
6 Correct 206 ms 63864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6096 ms 84784 KB Time limit exceeded
2 Halted 0 ms 0 KB -