답안 #32149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32149 2017-09-27T23:06:37 Z imaxblue Cities (BOI16_cities) C++14
0 / 100
2899 ms 87064 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;

int n, m, k, a, b, c, x, N, B, r;
ll dis[31][100005], t, D;
bool u[31][100005];
vector<pii> v[100005];
pq<pair<ll, int> > q;
int main(){
    scan(n); scan(k); scan(m);
    fox(l, (1 << k)-1){
        fox1(l2, n) dis[l][l2]=1152921504606846976LL;
    }
    fox(l, k){
        scan(a);
      	dis[1 << l][a]=0;
        q.push(mp(0, (1 << l) + (a << 5)));
    }
    fox(l, m){
        scan(a); scan(b); scan(c);
        v[a].pb(mp(b, c));
        v[b].pb(mp(a, c));
    }
    r=(1 << k)-2;
    while(!q.empty()){
        N=(q.top().y >> 5); D=-q.top().x; B=(q.top().y&31); q.pop();
        if (u[B][N]) continue;
        u[B][N]=1;
        //cout << N << ' ' << B << endl;
        if (B==r+1){
            cout << D << endl;
            return 0;
        }
        fox1(l, r){
            if (dis[B|l][N]>(t=D+dis[l][N])){
                dis[B|l][N]=t;
                q.push(mp(-t, (B|l)+(N << 5)));
            }
        }
        x=v[N].size();
        fox(l, x){
            if (dis[B][v[N][l].x]>(t=D+v[N][l].y)){
                dis[B][v[N][l].x]=t;
                q.push(mp(-t, B+(v[N][l].x << 5)));
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 31608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 749 ms 50204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 32136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2899 ms 87064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 139 ms 37812 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -