제출 #444757

#제출 시각아이디문제언어결과실행 시간메모리
444757arnold518도로 폐쇄 (APIO21_roads)C++17
24 / 100
2083 ms22504 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N; ll sum=0; vector<pii> adj[MAXN+10]; int par[MAXN+10], val[MAXN+10]; ll ans[MAXN+10]; int K; ll dp1[MAXN+10], dp2[MAXN+10]; void dfs(int now, int bef) { for(auto nxt : adj[now]) { if(nxt.first==bef) continue; dfs(nxt.first, now); par[nxt.first]=now; val[nxt.first]=nxt.second; } } void dfs2(int now, int bef) { vector<ll> V; ll p=0; for(auto nxt : adj[now]) { if(nxt.first==bef) continue; dfs2(nxt.first, now); V.push_back(dp1[nxt.first]-dp2[nxt.first]); p+=dp2[nxt.first]; } sort(V.begin(), V.end(), greater<ll>()); for(int i=0; i<K-1 && i<V.size(); i++) { if(V[i]>0) p+=V[i]; } dp1[now]=p+val[now]; if(K-1<V.size() && V[K-1]>0) p+=V[K-1]; dp2[now]=p; } vector<ll> minimum_closure_costs(int _N, vector<int> _U, vector<int> _V, vector<int> _W) { N=_N; for(int i=0; i<N-1; i++) { int u=_U[i], v=_V[i], w=_W[i]; adj[u].push_back({v, w}); adj[v].push_back({u, w}); sum+=w; } dfs(1, 1); for(K=0; K<N; K++) { dfs2(1, 1); ans[K]=sum-dp2[1]; } return vector<ll>(ans, ans+N); }

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

roads.cpp: In function 'void dfs2(int, int)':
roads.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=0; i<K-1 && i<V.size(); i++)
      |                        ~^~~~~~~~~
roads.cpp:48:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  if(K-1<V.size() && V[K-1]>0) p+=V[K-1];
      |     ~~~^~~~~~~~~
#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...