제출 #1137425

#제출 시각아이디문제언어결과실행 시간메모리
1137425icoder178Harbingers (CEOI09_harbingers)C++20
70 / 100
165 ms47320 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; #define int long long const int maxv = (int) 4e18; const int maxn = 100005; int n,dst[maxn],dp[maxn],rmv[maxn],s[maxn],v[maxn],ncnt = 0,rcnt = 0; pair<int,int> nconn[maxn],rmvd[maxn]; vector<pair<int,int> > conn[maxn],cht; inline void fdp(int pos) { int l = -5, r = cht.size()+5; while(l+1 < r) { int mid = (l+r)/2; bool isDecr; if(mid < 0) isDecr = true; else if(mid >= cht.size()-1) isDecr = false; else { int vl1 = cht[mid].second-v[pos]*cht[mid].first; int vl2 = cht[mid+1].second-v[pos]*cht[mid+1].first; isDecr = (vl2 < vl1); } if(isDecr == true) l = mid; else r = mid; } dp[pos] = cht[r].second-v[pos]*cht[r].first+v[pos]*dst[pos]+s[pos]; } inline void prmv(int pos) { int l = -5, r = cht.size()+5; while(l+1 < r) { int mid = (l+r)/2; bool isV; if(mid < 0) isV = true; else if(mid >= ((int) cht.size())-1) isV = false; else { __int128_t x1 = cht[mid].first; __int128_t y1 = cht[mid].second; __int128_t x2 = cht[mid+1].first; __int128_t y2 = cht[mid+1].second; __int128_t x3 = dst[pos]; __int128_t y3 = dp[pos]; __int128_t v1 = (y3-y2)*(x2-x1); __int128_t v2 = (y2-y1)*(x3-x2); isV = (v1 > v2); } if(isV) l = mid; else r = mid; } rmv[pos] = r+1; } void dfs(int pos, int prevP) { int ncl = ncnt; for(int i = 0; i < conn[pos].size(); i++) { int targP = conn[pos][i].first; int newV = conn[pos][i].second; if(targP != prevP) { dst[targP] = dst[pos]+newV; fdp(targP); prmv(targP); nconn[ncnt].first = rmv[targP]; nconn[ncnt].second = targP; ncnt++; } } int ncr = ncnt; sort(nconn+ncl,nconn+ncr); int rcl = rcnt; for(int i = ncr-1; i >= ncl; i--) { while(cht.size() > nconn[i].first) { rmvd[rcnt] = cht.back(); rcnt++; cht.pop_back(); } int targP = nconn[i].second; cht.push_back(make_pair(dst[targP],dp[targP])); dfs(targP,pos); cht.pop_back(); } ncnt = ncl; int rcr = rcnt; for(int i = rcr-1; i >= rcl; i--) { cht.push_back(rmvd[i]); } rcnt = rcl; } signed main () { scanf("%lld",&n); for(int i = 0; i < n-1; i++) { int a,b,c; scanf("%lld%lld%lld",&a,&b,&c); conn[a].push_back(make_pair(b,c)); conn[b].push_back(make_pair(a,c)); } for(int i = 2; i <= n; i++) { scanf("%lld%lld",&s[i],&v[i]); } cht.push_back(make_pair(0,0)); dfs(1,-1); for(int i = 2; i <= n; i++) { printf("%lld ",dp[i]); } printf("\n"); return 0; }

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

harbingers.cpp: In function 'int main()':
harbingers.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
harbingers.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         scanf("%lld%lld%lld",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
harbingers.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         scanf("%lld%lld",&s[i],&v[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...