제출 #344444

#제출 시각아이디문제언어결과실행 시간메모리
344444wwdd구슬과 끈 (APIO14_beads)C++14
0 / 100
1 ms896 KiB
//gross #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll,ll> pl; typedef vector<pl> vpl; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vpl> al; struct EG { ll st,ed,wo; }; const ll INFL = 1e18; const int MN = 200200; ll dp[MN][2]; bool bp[MN][2]; vl lev; vvi g; void dfa(int u, int p) { if(u != p) { lev[u] = lev[p]+1; } for(int i=0;i<g[u].size();i++) { int v = g[u][i]; if(v == p) {continue;} dfa(v,u); } } vl ko; ll ds(int u, int p, int m) { if(bp[u][m]) { return dp[u][m]; } ll res; if(m) { if(g[u].size() >= 1) { res = 0; ll ma = -INFL; for(int i=0;i<g[u].size();i++) { int v = g[u][i]; if(v == p) {continue;} ll mv = max(ko[v]+ds(v,u,1),ds(v,u,0)); res += mv; ma = max(ma,ko[v]+ds(v,u,0)-mv); } res += ma; } else { res = -INFL; } } else { res = 0; vl du; for(int i=0;i<g[u].size();i++) { int v = g[u][i]; if(v == p) {continue;} ll mv = max(ds(v,u,0),ko[v]+ds(v,u,1)); res += mv; du.push_back(ko[v]+ds(v,u,0)-mv); } if(du.size() >= 2) { sort(du.rbegin(),du.rend()); if(du[0]+du[1] >= 0) { res += du[0]+du[1]; } } } bp[u][m] = true; return dp[u][m] = res; } int main() { ios::sync_with_stdio(0);cin.tie(0); memset(bp,0,sizeof(bp)); ll n; cin >> n; lev.assign(n,0); g.assign(n,vi()); ko.assign(n,0); vector<EG> el; for(int i=1;i<n;i++) { ll a,b,c; cin >> a >> b >> c; a--;b--; g[a].push_back(b); g[b].push_back(a); el.push_back({a,b,c}); } dfa(0,0); for(int i=0;i<el.size();i++) { ll a = el[i].st; ll b = el[i].ed; if(lev[a] > lev[b]) {swap(a,b);} ko[b] = el[i].wo; } cout << ds(0,0,0) << '\n'; }

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

beads.cpp: In function 'void dfa(int, int)':
beads.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i=0;i<g[u].size();i++) {
      |              ~^~~~~~~~~~~~
beads.cpp: In function 'll ds(int, int, int)':
beads.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    for(int i=0;i<g[u].size();i++) {
      |                ~^~~~~~~~~~~~
beads.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i=0;i<g[u].size();i++) {
      |               ~^~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:89:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<EG>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(int i=0;i<el.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...