Submission #96250

# Submission time Handle Problem Language Result Execution time Memory
96250 2019-02-07T12:58:30 Z easrui Cities (BOI16_cities) C++14
100 / 100
2447 ms 42448 KB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int MN = 1e5+5;
long long N,K,M,A,B,d,sz,Im[5],cur,tmp,cost,ans,D[32][MN];
vector<pii> G[MN];
priority_queue<pii> Q;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> K >> M;
    for(int i=0; i<K; i++) cin >> Im[i];
    for(int i=0; i<M; i++){
        cin >> A >> B >> d;
        G[A].push_back(pii(B,d));
        G[B].push_back(pii(A,d));
    }
    sz = 1<<K;
    for(int i=0; i<sz; i++)
        for(int j=1; j<=N; j++) D[i][j] = 1e18;
    for(int j=0; j<K; j++) D[(1<<j)][Im[j]] = 0;
    for(int i=1; i<sz; i++){
        for(int j=1; j<=N; j++){
            tmp = 1e18;
            for(int p=1; p<sz; p++){
                if((p&i)!=p) continue;
                tmp = min(tmp,D[i-p][j] + D[p][j]);
            }
            D[i][j] = min(D[i][j],tmp);
            Q.emplace(-D[i][j],j);
        }
        while(!Q.empty()){
            cur = Q.top().vb;
            cost = -Q.top().va;
            Q.pop();
            if(cost>D[i][cur]) continue;
            for(pii x : G[cur]){
                if(D[i][x.va] > cost + x.vb){
                    D[i][x.va] = cost + x.vb;
                    Q.emplace(-D[i][x.va],x.va);
                }
            }
        }
    }
    ans = 1e18;
    for(int j=1; j<=N; j++) ans = min(ans,D[sz-1][j]);
    cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 3 ms 2680 KB Output is correct
3 Correct 3 ms 2680 KB Output is correct
4 Correct 3 ms 2808 KB Output is correct
5 Correct 4 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 23648 KB Output is correct
2 Correct 675 ms 22764 KB Output is correct
3 Correct 418 ms 16364 KB Output is correct
4 Correct 75 ms 11768 KB Output is correct
5 Correct 336 ms 20596 KB Output is correct
6 Correct 81 ms 11768 KB Output is correct
7 Correct 6 ms 3064 KB Output is correct
8 Correct 7 ms 2940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3108 KB Output is correct
2 Correct 8 ms 3064 KB Output is correct
3 Correct 7 ms 2936 KB Output is correct
4 Correct 6 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1162 ms 29756 KB Output is correct
2 Correct 1124 ms 29044 KB Output is correct
3 Correct 911 ms 22632 KB Output is correct
4 Correct 721 ms 21736 KB Output is correct
5 Correct 195 ms 14420 KB Output is correct
6 Correct 88 ms 14268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2301 ms 42388 KB Output is correct
2 Correct 2367 ms 42448 KB Output is correct
3 Correct 2447 ms 41444 KB Output is correct
4 Correct 1736 ms 35180 KB Output is correct
5 Correct 1338 ms 28008 KB Output is correct
6 Correct 302 ms 15628 KB Output is correct
7 Correct 96 ms 14200 KB Output is correct