제출 #717976

#제출 시각아이디문제언어결과실행 시간메모리
717976guagua0407Harbingers (CEOI09_harbingers)C++17
100 / 100
164 ms21180 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct line{ ll a,b; ll operator()(const ll x){ return a*x+b; } }; const ll mxn=1e5+5; vector<pair<ll,ll>> adj[mxn]; ll S[mxn]; ll V[mxn]; line li[mxn]; ll depth[mxn]; ll dp[mxn]; int vec[mxn]; int cur_size=1; void dfs0(ll v,ll p){ for(auto u:adj[v]){ if(u.f==p) continue; depth[u.f]=depth[v]+u.s; dfs0(u.f,v); } } bool check(ll a,ll b,ll c){ line l1=li[a]; line l2=li[b]; line l3=li[c]; return (long double)(l2.b-l3.b)/(l3.a-l2.a)<(long double)(l1.b-l2.b)/(l2.a-l1.a); } void dfs(ll v,ll p){ ll l=0,r=cur_size-1; while(l<r){ ll mid=(l+r)/2; if(li[vec[mid]](V[v])<=li[vec[mid+1]](V[v])){ r=mid; } else{ l=mid+1; } } dp[v]=S[v]+depth[v]*V[v]+li[vec[l]](V[v]); li[v]={-depth[v],dp[v]}; l=0,r=cur_size-1; while(l<r){ ll mid=(l+r)/2; if(check(vec[mid],vec[mid+1],v)){ r=mid; } else{ l=mid+1; } } int prv_size=cur_size; int prv_index=vec[l+1]; cur_size=l+2; vec[l+1]=v; for(auto u:adj[v]){ if(u.f==p) continue; dfs(u.f,v); } cur_size=prv_size; vec[l+1]=prv_index; } int main() {_ ll n; cin>>n; for(ll i=0;i<n-1;i++){ ll d,u,v; cin>>u>>v>>d; adj[u].push_back({v,d}); adj[v].push_back({u,d}); } for(ll i=2;i<=n;i++){ cin>>S[i]>>V[i]; } dfs0(1,0); vec[0]=0; dfs(1,0); for(ll i=2;i<=n;i++){ cout<<dp[i]<<' '; } return 0; } //maybe its multiset not set

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

harbingers.cpp: In function 'void setIO(std::string)':
harbingers.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
harbingers.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...