제출 #684400

#제출 시각아이디문제언어결과실행 시간메모리
684400PoonYaPatFireworks (APIO16_fireworks)C++14
26 / 100
16 ms26324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,l[300001],r[300001],w[300001]; ll Ymin[300001]; vector<int> adj[300001]; priority_queue<int, vector<int>, greater<int>> rsq[300001]; priority_queue<int> lsq[300001]; void dfs(int x) { int cnt=0; priority_queue<int, vector<int>, greater<int>> temp; if (!adj[x].size()) { l[x]=w[x]; r[x]=w[x]; Ymin[x]=0; lsq[x].push(l[x]); rsq[x].push(r[x]); return; } for (auto s : adj[x]) { ++cnt; dfs(s); Ymin[x]+=Ymin[s]; if (lsq[x].size()) { if (l[s]>r[x]) Ymin[x]+=l[s]-r[x]; if (r[s]<l[x]) Ymin[x]+=l[x]-r[s]; } if (lsq[s].size()+rsq[s].size()>lsq[x].size()+temp.size()) swap(lsq[x],lsq[s]), swap(temp,rsq[s]); if (lsq[x].size()) { while (!lsq[s].empty()) { if (lsq[s].top()>=temp.top()) temp.push(lsq[s].top()); else lsq[x].push(lsq[s].top()); lsq[s].pop(); } while (!rsq[s].empty()) { if (rsq[s].top()>=temp.top()) temp.push(rsq[s].top()); else lsq[x].push(rsq[s].top()); rsq[s].pop(); } } while (temp.size()>cnt) lsq[x].push(temp.top()), temp.pop(); while (temp.size()<cnt) temp.push(lsq[x].top()), lsq[x].pop(); l[x]=lsq[x].top(); r[x]=temp.top(); } l[x]+=w[x]; r[x]+=w[x]; lsq[x].pop(); lsq[x].push(l[x]); rsq[x].push(r[x]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for (int i=2; i<=n+m; ++i) { int u; cin>>u>>w[i]; adj[u].push_back(i); } dfs(1); cout<<Ymin[1]; }

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

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:50:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         while (temp.size()>cnt) lsq[x].push(temp.top()), temp.pop();
      |                ~~~~~~~~~~~^~~~
fireworks.cpp:51:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |         while (temp.size()<cnt) temp.push(lsq[x].top()), lsq[x].pop();
      |                ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...