이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "roads.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 1LL << 60;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
int n;
vector<vector<pii>> g;
vector<ll> dp1, dp2;
int k;
void dfs(int now, int p, int w){
ll sum = 0;
vector<ll> tmp;
for(pii i : g[now]){
if(i.F == p) continue;
dfs(i.F, now, i.S);
sum += dp2[i.F];
tmp.eb(dp1[i.F] - dp2[i.F]);
}
lsort(tmp);
for(int i = 0; i < k - 1 && i < tmp.size(); i++){
sum += tmp[i];
}
dp1[now] = sum;
if(k - 1 < tmp.size()) sum += tmp[k - 1];
dp2[now] = sum + w;
}
ll solve(int K){
k = K;
dp1.clear(); dp1.resize(n, MAX);
dp2.clear(); dp2.resize(n, MAX);
dfs(0, 0, 0);
// cerr << "test " << K << "\n";
// printv(dp1, cerr);
// printv(dp2, cerr);
return dp2[0];
}
vector<ll> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W){
n = N;
g.resize(n);
for(int i = 0; i < n - 1; i++){
int u = U[i], v = V[i], w = W[i];
g[u].eb(mp(v, w));
g[v].eb(mp(u, w));
}
vector<ll> ans(n);
for(int i = 0; i < n; i++) ans[i] = solve(i);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
roads.cpp: In function 'void dfs(int, int, int)':
roads.cpp:81:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int i = 0; i < k - 1 && i < tmp.size(); i++){
| ~~^~~~~~~~~~~~
roads.cpp:85:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if(k - 1 < tmp.size()) sum += tmp[k - 1];
| ~~~~~~^~~~~~~~~~~~
# | 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... |