제출 #713092

#제출 시각아이디문제언어결과실행 시간메모리
713092BobonbushHarbingers (CEOI09_harbingers)C++17
0 / 100
5 ms3540 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #define foreach for #define in : using namespace std; typedef long long ll; int MODULO =1e9+7 ; const long long INF = 1e18+7; const unsigned long long LIMIT = 2e18; /* Konichiwa Konichiwa Ara ~~ ara Bob no taisuki - Shinobu Kocho * * * * * * * * * * * I love SHINOBU <3 <3 <3 * * * * * * * * * */ /* _________________________ Author : Bob15324 _________________________ */ /* okay i'm hoping that somebody pray for me I'm praying that somebody hope for me I'm staying where nobody 'posed to be p-p-posted being a wreak of emotions ready to go whenever just let me know the road is long so put the pedal into the floor the enemy's on my trail my energy unavailble Imma tell em hasta luego they wanna plot on my trot to the top I've been outta shape thinking out the box I'm an astronaut i balsted off the planet rock to cause catastrophe and it matters more because i had it not had i thought about wreaking havoc on an opposition kinda shocking they wanted static with precision i'm automatic quarterback i ain't talking sacking pack itpack it up i don't panic who the baddest it doesn't matter cause we at ya throat */ // EVERYBODY WANT TO BE MY ENEMY template<class X , class Y> bool Minimize(X & x , Y y) { if( x > y ) { x = y; return true; } return false; } template<class X , class Y> bool Maximize(X & x , Y y) { if( x < y) { x = y; return true; } return false; } template<class X , class Y> void Add(X &x , Y y ) { x += y; if(x >= MODULO) { x -= MODULO; } } template<class X , class Y> void Sub(X &x ,Y y) { x -= y; if(x < 0) { x += MODULO; } } template<class X , class Y> bool Check_MUL(X x , Y y ) { return x > LIMIT/y; } /* End of templates. Let's see what do we have here */ const int N = 1e5+1; int n ; vector<pair<int ,int >>vertices[N]; struct mailer { int s , v; mailer(int _s ,int _v) { s = _s; v = _v; } mailer() { s = 0; v = 0; } }mail[N]; struct Lines { long long a , b ; int u ; Lines(long long _a , long long _b ,int _u) { a = _a; b = _b; u = _u; } long long operator() (long long x) const {return a * x + b;} }; deque<Lines>dq; bool bad(Lines &l1 , Lines &l2 , Lines & l3) { return (long double) (l3.b - l1.b) *(l1.a - l2.a) < (long double) (l2.b - l1.b) *(l1.a - l3.a); } void add(Lines line , vector<Lines> & List) { while((int)dq.size() >= 2 && bad(dq[(int)dq.size() - 2] , dq[(int)dq.size()-1] , line) ) { List.push_back(dq.back()); dq.pop_back(); } dq.push_back(line); } long long Get(long long x , vector<Lines> &List) { while((int)dq.size() >= 2 && dq[0] (x) <= dq[1](x) ) { List.push_back(dq.front()); dq.pop_front(); } return dq.front()(x); } void del(int u) { if(dq.empty())return ; if(dq.back().u == u) { dq.pop_back(); } } long long ans[N]; long long dist[N]; void DFS(int u ,int daddy) { vector<Lines>get , d; ans[u] = dist[u] * 1LL * mail[u].v - Get(mail[u].v , get) + mail[u].s ; add(Lines( dist[u] , -ans[u] , u) ,d); foreach(pair<int ,int >&adj in vertices[u]) { int v = adj.first; int w = adj.second; if(v == daddy)continue; dist[v] = dist[u] + w; DFS(v ,u ); } del(u); foreach(Lines &l in d)dq.push_back(l); foreach(Lines &l in get)dq.push_front(l); } void Input() { cin >> n ; for(int i =1 ; i <= n-1 ; i++) { int u , v , w; cin >> u >> v >> w; vertices[u].push_back(make_pair(v , w)); vertices[v].push_back(make_pair(u , w)); } mail[1] = mailer(0 , 0); for(int i =2 ; i <= n ; i++) { cin >> mail[i].s >> mail[i].v; } } void Process() { dq.push_back(Lines(0 , 0, 1)); foreach(pair<int ,int >& adj in vertices[1]) { int v = adj.first; int w = adj.second; dist[v] = w; DFS(v , 1); assert(dq.front().a == 0 && dq.front().b == 0 && dq.front().u == 1 && (int)dq.size() == 1); } for(int i =2 ; i <= n ; i++)cout << ans[i] <<' '; } int main() { ios_base :: sync_with_stdio(0);cin.tie(0); freopen("harbingers.in","r",stdin); freopen("harbingers.out","w",stdout); int test; test = 1; while(test--) { Input(); Process(); cout <<'\n'; } return 0; } //Ehem. My code is amazing. Pay me 2$.Thank you.

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

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