Submission #27468

# Submission time Handle Problem Language Result Execution time Memory
27468 2017-07-13T05:50:56 Z top34051 Cities (BOI16_cities) C++14
0 / 100
4000 ms 50696 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define inf (long long)1e16
struct node {
    int x,bit;
    long long val;
    node(int _x = 0,int _bit = 0,long long _val = 0) {
        x = _x; bit = _bit; val = _val;
    }
    bool operator < (node a) const {
        return a.val<val;
    }
};
int n,k,m;
int p2[10];
int sp[maxn];
long long mem[maxn][35];
vector<pair<int,int> > from[maxn];
priority_queue<node> heap;
main() {
    int i,x,y,val,bit;
    node t;
    scanf("%d%d%d",&n,&k,&m);
    for(i=1;i<=n;i++) sp[i] = -1;
    for(i=0;i<k;i++) scanf("%d",&x), sp[x] = i;
    while(m--) {
        scanf("%d%d%d",&x,&y,&val);
        from[x].push_back({y,val}); from[y].push_back({x,val});
    }
    p2[-1] = 0; p2[0] = 1;
    for(i=1;i<=k;i++) p2[i] = p2[i-1]*2;
    for(x=1;x<=n;x++) {
        for(bit=0;bit<p2[k];bit++) mem[x][bit] = inf;
        if(sp[x]!=-1) {
            mem[x][p2[sp[x]]] = 0;
            heap.push(node(x,p2[sp[x]],0));
        }
    }
    while(!heap.empty()) {
        t = heap.top(); heap.pop();
        if(t.bit==p2[k]-1) {
            printf("%lld",t.val);
            return 0;
        }
//        for(bit=0;bit<p2[k];bit++) {
//            if(mem[t.x][t.bit|bit] > mem[t.x][t.bit] + mem[t.x][bit]) {
//                mem[t.x][t.bit|bit] = mem[t.x][t.bit] + mem[t.x][bit];
//                heap.push(node(t.x,t.bit|bit,mem[t.x][t.bit|bit]));
//            }
//        }
        for(i=0;i<from[t.x].size();i++) {
            y = from[t.x][i].first; val = from[t.x][i].second;
            if(mem[y][t.bit|p2[sp[y]]] > mem[t.x][t.bit] + val) {
                mem[y][t.bit|p2[sp[y]]] = mem[t.x][t.bit] + val;
                heap.push(node(y,t.bit|p2[sp[y]],mem[y][t.bit|p2[sp[y]]]));
            }
        }
    }
}

Compilation message

cities.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
cities.cpp: In function 'int main()':
cities.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[t.x].size();i++) {
                  ^
cities.cpp:24:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&k,&m);
                             ^
cities.cpp:26:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=0;i<k;i++) scanf("%d",&x), sp[x] = i;
                                               ^
cities.cpp:28:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&val);
                                   ^
cities.cpp:31:10: warning: array subscript is below array bounds [-Warray-bounds]
     p2[-1] = 0; p2[0] = 1;
          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32100 KB Output is correct
2 Correct 0 ms 32100 KB Output is correct
3 Incorrect 0 ms 32100 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 706 ms 44556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 32368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1436 ms 44548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4000 ms 50696 KB Execution timed out
2 Halted 0 ms 0 KB -