답안 #113709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113709 2019-05-28T01:56:15 Z thebes Cities (BOI16_cities) C++14
14 / 100
4483 ms 135192 KB
#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; ll d;};

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;
struct pq{bool operator()(const reeee&i,const reeee&j){return i.d>j.d;}};
priority_queue<reeee,vector<reeee>,pq> q;
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++)
        q.push({heh[i], 1<<i, 0});
    while(q.size()){
        reeee v;
        if(idk.size()) v = idk.front(), idk.pop();
        else v = q.top(), q.pop();
        if(v.m==(1<<k)-1) ans = min(ans, v.d);
        if(ww[v.n][v.m]) continue;
        vs[v.n][v.m] = v.d;
        ww[v.n][v.m] = 1;
        for(int mm=0;mm<(1<<k);mm++){
            if(v.d+vs[v.n][mm]<vs[v.n][v.m|mm]){
                vs[v.n][v.m|mm]=v.d+vs[v.n][mm];
                idk.push({v.n, v.m|mm, v.d+vs[v.n][mm]});
            }
        }
        for(auto w : adj[v.n]){
            if(v.d+w.second<vs[w.first][v.m]){
                vs[w.first][v.m]=v.d+w.second;
                q.push({w.first, v.m, v.d+w.second});
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:27:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<heh.size();i++)
             ~^~~~~~~~~~~
cities.cpp:28:33: 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]
         q.push({heh[i], 1<<i, 0});
                                 ^
cities.cpp:46:27: warning: narrowing conversion of 'w.std::pair<long long int, long long int>::first' from 'long long int' to 'int' inside { } [-Wnarrowing]
                 q.push({w.first, v.m, v.d+w.second});
                         ~~^~~~~
cities.cpp:17: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:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
cities.cpp:22: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 52728 KB Output is correct
2 Correct 43 ms 52856 KB Output is correct
3 Correct 43 ms 52856 KB Output is correct
4 Correct 42 ms 52736 KB Output is correct
5 Incorrect 43 ms 52856 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 925 ms 77784 KB Output is correct
2 Correct 871 ms 76892 KB Output is correct
3 Correct 471 ms 66612 KB Output is correct
4 Correct 318 ms 62844 KB Output is correct
5 Correct 489 ms 73700 KB Output is correct
6 Correct 134 ms 61936 KB Output is correct
7 Correct 45 ms 53112 KB Output is correct
8 Correct 44 ms 52984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 53384 KB Output is correct
2 Correct 51 ms 53368 KB Output is correct
3 Correct 45 ms 52984 KB Output is correct
4 Incorrect 49 ms 53252 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1989 ms 102472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4483 ms 135192 KB Output isn't correct
2 Halted 0 ms 0 KB -