이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "roads.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5, oo = 1e18 + 7, mod = 1e9 + 7;
ll n;
vector<ii> Adj[N];
ll k;
ll dp[N][2];
bool vis[N];
void dfs(int u, int p){
vis[u] = 1;
int we = 0;
for(auto it : Adj[u]){
int v = it.fi;
if(v == p){
we = it.se;
continue;
}
if(Adj[v].size() <= k) continue;
dfs(v, u);
}
vector<ll> vc;
ll sum = 0;
for(auto it : Adj[u]){
int v = it.fi;
if(v == p) continue;
if(Adj[v].size() > k){
sum += dp[v][0];
vc.pb(dp[v][0] - dp[v][1]);
}
else{
sum += it.se;
vc.pb(it.se);
}
}
sort(vc.begin(), vc.end());
reverse(vc.begin(), vc.end());
ll sum2 = 0;
for(int i = 0; i < min((ll)vc.size(), (ll)k - 1); i++){
sum2 += max(0LL, vc[i]);
}
dp[u][0] = sum - sum2 - (((ll)vc.size() < k || !k) ? 0 : max(0LL, vc[k - 1])) + we;
dp[u][1] = sum - sum2;
//cout << u << " " << dp[u][0] << " " << dp[u][1] << "\n";
}
bool ck_star(){
int tol = 0;
for(int i= 1; i <= n; i++) tol += (Adj[i].size() >= 2);
return (tol == 1);
}
bool ck_line(){
for(int i = 1; i <= n; i++) if(Adj[i].size() > 2) return 0;
return 1;
}
vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W){
n = N;
//cout << U.size() << " " << V.size() << " " << W.size() << "\n";
//exit(0);
for(int i = 0; i < (n - 1); i++){
U[i]++, V[i]++;
Adj[U[i]].pb({V[i], W[i]});
Adj[V[i]].pb({U[i], W[i]});
}
if(ck_star()){
sort(W.begin(), W.end(), greater<int>());
vector<ll> ans(n);
ll sum = 0;
for(int i = n - 1; i >= 0; i--){
ans[i] = sum;
if(i) sum += W[i - 1];
}
return ans;
}
int mx_deg = 0;
for(int i = 1; i <= n; i++) mx_deg = max(mx_deg, (int)Adj[i].size());
vector<ll> ans;
for(int i = 0; i < mx_deg; i++){
k = i;
for(int j = 1; j <= n; j++) vis[j] = 0;
ll answ = 0;
for(int j = 1; j <= n; j++){
if(!vis[j] && Adj[j].size() > k){
dfs(j, j);
answ += dp[j][0];
}
}
ans.pb(answ);
/*
k = i;
dfs(1, 1);
ans.pb(min(dp[1][0], dp[1][1]));*/
}
for(int i = mx_deg; i < n; i++) ans.pb(0);
return ans;
}
/*
void process(){
int n;
vector<int> a, b, c;
cin >> n;
for(int i = 1; i <= 3 * n - 3; i++){
int x;
cin >> x;
if(i <= (n - 1)) a.pb(x);
else if(i <= 2 * (n - 1)) b.pb(x);
else c.pb(x);
}
vector<long long> temp = minimum_closure_costs(n, a, b, c);
for(auto it : temp) cout << it << " ";
}
signed main(){
ios_base::sync_with_stdio(0);
freopen("roads.inp", "r", stdin);
freopen("roads.out", "w", stdout);
process();
}*/
컴파일 시 표준 에러 (stderr) 메시지
roads.cpp:14:34: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
14 | const int N = 1e5 + 5, oo = 1e18 + 7, mod = 1e9 + 7;
| ~~~~~^~~
roads.cpp: In function 'void dfs(int, int)':
roads.cpp:34:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
34 | if(Adj[v].size() <= k) continue;
| ~~~~~~~~~~~~~~^~~~
roads.cpp:42:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
42 | if(Adj[v].size() > k){
| ~~~~~~~~~~~~~~^~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:100:32: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
100 | if(!vis[j] && Adj[j].size() > k){
| ~~~~~~~~~~~~~~^~~
# | 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... |