이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "roads.h"
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
vector<vector<pair<int,int>>> G(100100);
map<pair<int,bool>,ll> m;
int bor = 0;
int f(int x, int par, bool p){
if(m.count({x,p})) return m[{x,p}];
int ed = p;
vector<ll> S = {};
for(auto y:G[x]){
int u,w;
tie(u,w) = y;
if(par == u) continue;
m[{x,p}] += f(u,x,false)+w;
S.push_back(f(u,x,true)-(f(u,x,false)+w));
}
sort(S.begin(),S.end());
int now = 0;
if(ed > bor) return 1e9;
while(ed < bor && now != S.size() && S[now] < 0){
ed++;
m[{x,p}] += S[now];
now++;
}
return m[{x,p}];
}
std::vector<ll> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
for(int i=0;i<W.size();i++){
G[U[i]].push_back({V[i],W[i]});
G[V[i]].push_back({U[i],W[i]});
}
vector<ll> A = {};
for(int i=0;i<N;i++){
bor = i;
m.clear();
A.push_back(f(0,-1,false));
}
return A;
}
컴파일 시 표준 에러 (stderr) 메시지
roads.cpp: In function 'int f(int, int, bool)':
roads.cpp:25:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while(ed < bor && now != S.size() && S[now] < 0){
| ~~~~^~~~~~~~~~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i=0;i<W.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |