답안 #27706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27706 2017-07-13T13:51:22 Z top34051 Cities (BOI16_cities) C++14
74 / 100
4000 ms 44560 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define inf (long long)1e16
struct node {
    int x;
    long long val;
    node(int _x = 0,long long _val = 0) {
        x = _x; 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<int> can[35];
vector<pair<int,int> > from[maxn];
priority_queue<node> heap;
void mssp(int bit) {
    int i,y,val;
    node t;
    for(i=1;i<=n;i++) heap.push(node(i,mem[i][bit]));
    while(!heap.empty()) {
        t = heap.top(); heap.pop();
        if(t.val>mem[t.x][bit]) continue ;
        for(i=0;i<from[t.x].size();i++) {
            y = from[t.x][i].first; val = from[t.x][i].second;
            if(mem[y][bit] > mem[t.x][bit] + val) {
                mem[y][bit] = mem[t.x][bit] + val;
                heap.push(node(y,mem[y][bit]));
            }
        }
    }
}
main() {
    int i,j,x,y,val,bit;
    long long ans;
    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(i=0;i<p2[k];i++) for(j=0;j<p2[k];j++) if(((i&j)==j) && i>=j) can[i].push_back(j);
    for(x=1;x<=n;x++) {
        for(bit=0;bit<p2[k];bit++) mem[x][bit] = inf;
        mem[x][p2[sp[x]]] = 0;
    }
    for(bit=0;bit<p2[k];bit++) {
        for(x=1;x<=n;x++) for(i=0;i<can[bit].size();i++) mem[x][bit] = min(mem[x][bit],mem[x][can[bit][i]] + mem[x][bit^can[bit][i]]);
        mssp(bit);
    }
    ans = inf;
    for(i=1;i<=n;i++) ans = min(ans,mem[i][p2[k]-1]);
    printf("%lld",ans);
}

Compilation message

cities.cpp: In function 'void mssp(int)':
cities.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[t.x].size();i++) {
                  ^
cities.cpp: At global scope:
cities.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
cities.cpp: In function 'int main()':
cities.cpp:57:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(x=1;x<=n;x++) for(i=0;i<can[bit].size();i++) mem[x][bit] = min(mem[x][bit],mem[x][can[bit][i]] + mem[x][bit^can[bit][i]]);
                                    ^
cities.cpp:42: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:44: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:46: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:49:10: warning: array subscript is below array bounds [-Warray-bounds]
     p2[-1] = 0; p2[0] = 1;
          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 32104 KB Output is correct
2 Correct 0 ms 32104 KB Output is correct
3 Correct 0 ms 32104 KB Output is correct
4 Correct 0 ms 32104 KB Output is correct
5 Correct 0 ms 32104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1259 ms 44560 KB Output is correct
2 Correct 966 ms 44488 KB Output is correct
3 Correct 829 ms 38384 KB Output is correct
4 Correct 153 ms 36644 KB Output is correct
5 Correct 749 ms 44552 KB Output is correct
6 Correct 123 ms 36732 KB Output is correct
7 Correct 3 ms 32236 KB Output is correct
8 Correct 3 ms 32236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 32236 KB Output is correct
2 Correct 6 ms 32236 KB Output is correct
3 Correct 3 ms 32244 KB Output is correct
4 Correct 3 ms 32236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2526 ms 44552 KB Output is correct
2 Correct 1996 ms 44344 KB Output is correct
3 Correct 989 ms 38388 KB Output is correct
4 Correct 876 ms 40988 KB Output is correct
5 Correct 276 ms 38904 KB Output is correct
6 Correct 156 ms 38396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4000 ms 44556 KB Execution timed out
2 Halted 0 ms 0 KB -