제출 #981357

#제출 시각아이디문제언어결과실행 시간메모리
981357sleepntsheep도로 폐쇄 (APIO21_roads)C++14
컴파일 에러
0 ms0 KiB
long long dir(long long x){return x<0?-1:x>0?1:0;} #define assert(x) if(!(x))__builtin_trap() #include "roads.h" #include<stdlib.h> #include <vector> #define NN 2000 #define MM (2*NN) int head[NN], nxt[MM], vv[MM], ww[MM]; void link(int u,int v,int w) { static int i=1; nxt[i]=head[u]; vv[i]=v; ww[i]=w; head[u]=i++; } long long dp_loose[NN], dp_tight[NN]; typedef struct { long long a, b; } ab; int abdec(ab a, ab b) { if(a.a^b.a)return -dir(a.a-b.a);return -dir(a.b-b.b);} int ij(const void*ii,const void*jj){return -dir(*(const long long*)ii-*(const long long*)jj);} void dfs(int u,int p,int k) { for(int j=head[u];j;j=nxt[j])if(vv[j]-p) dfs(vv[j], u, k); static long long aa[NN]; long long sum = 0; int ao = 0; for(int j=head[u];j;j=nxt[j])if(vv[j]-p) { int v=vv[j],w=ww[j]; aa[ao] = w + dp_loose[v] - dp_tight[v]; if (aa[ao] >= 0) ++ao; sum += dp_tight[v]; } /* for tight : can have at most k loose children * */ qsort(aa, ao, sizeof*aa, ij); int i; for(i=k;i<ao;++i) sum += aa[i]; dp_loose[u] = sum; if(k-1>=0&&k-1<ao) sum += aa[k-1]; dp_tight[u] = sum; } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { if(N>2000)__builtin_unreachable(); for(int i=0;i<N-1;++i)link(U[i],V[i],W[i]),link(V[i],U[i],W[i]); std::vector<long long> ans(N); for(int k=0;k<N;++k) dfs(0, 0, k), ans[k] = dp[0][1]; return ans; }

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

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:66:32: error: 'dp' was not declared in this scope
   66 |         dfs(0, 0, k), ans[k] = dp[0][1];
      |                                ^~