제출 #1111000

#제출 시각아이디문제언어결과실행 시간메모리
1111000razivoMagic Tree (CEOI19_magictree)C++14
0 / 100
2075 ms28052 KiB
#include <iostream> #include <set> #include <vector> int n,m,k; using namespace std; typedef long long ll; typedef set<pair<int,ll>> sp; typedef pair<int,int> pi; void add(sp &a, int from, ll v) { auto q = a.lower_bound({from,0}); bool b = false; while(true) { auto q = a.lower_bound({from,0}); if(q==a.end()) break; if(q->second<v) { bool b = true; a.erase(q); }else break; } a.insert({from,v}); } ll eval(sp &a, int at) { auto q = a.lower_bound({at+1,0}); --q; return q->second; } sp un(sp &a, sp &b) { sp res; auto q = a.begin(); auto p = b.begin(); int pos = 0; ll vala = 0; ll valb = 0; while(!((q==a.end()) &&(p==b.end()))) { res.insert({pos,vala+valb}); if(q==a.end()) { ++p; valb= p->second; pos = p->first; }else if(p==b.end()) { ++q; vala= q->second; pos = q->first; }else { if(q->second>p->second) { ++p; valb= p->second; pos = p->first; }else { ++q; vala= q->second; pos = q->first; } } } return res; } sp dfs(int cur, vector<vector<int>> &c,vector<pair<int,int>> &f) { if(c[cur].empty()) { sp a = {{0,0}}; add(a,f[cur].first,f[cur].second); return a; }else { vector<sp> sets; int locmax = 0; int valmax = 0; for (int i :c[cur]) { sets.push_back(dfs(i,c,f)); if(sets.back().size()>valmax) { locmax= sets.size()-1; valmax = sets.back().size(); } } for (int i = 0; i < sets.size(); ++i) { if(i==locmax) continue; sets[locmax] = un(sets[locmax],sets[i]); } if(f[cur].second!= 0) { ll a = eval(sets[locmax], f[cur].first); add(sets[locmax],f[cur].first,f[cur].second+a); } return sets[locmax]; } } int main() { cin>>n>>m>>k; vector<vector<int>> c(n); for (int i = 1; i < n; ++i) { int x; cin>>x; x--; c[x].push_back(i); } vector<pair<int,int>> f(n,{0,0}); for (int i = 0; i < m; ++i) { int x,y,z; cin>>x>>y>>z; x--; y--; f[x]={y,z}; } sp s = dfs(0,c,f); cout<<eval(s,k)<<endl; }

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

magictree.cpp: In function 'void add(sp&, int, ll)':
magictree.cpp:16:18: warning: unused variable 'b' [-Wunused-variable]
   16 |             bool b = true;
      |                  ^
magictree.cpp:10:10: warning: variable 'q' set but not used [-Wunused-but-set-variable]
   10 |     auto q = a.lower_bound({from,0});
      |          ^
magictree.cpp:11:10: warning: unused variable 'b' [-Wunused-variable]
   11 |     bool b = false;
      |          ^
magictree.cpp: In function 'sp dfs(int, std::vector<std::vector<int> >&, std::vector<std::pair<int, int> >&)':
magictree.cpp:69:34: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |             if(sets.back().size()>valmax) {
      |                ~~~~~~~~~~~~~~~~~~^~~~~~~
magictree.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<std::pair<int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int i = 0; i < sets.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...