제출 #27467

#제출 시각아이디문제언어결과실행 시간메모리
27467top34051Cities (BOI16_cities)C++14
51 / 100
4000 ms235020 KiB
#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]]])); } } } }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...