Submission #981990

#TimeUsernameProblemLanguageResultExecution timeMemory
981990steveonalexRoad Closures (APIO21_roads)C++17
24 / 100
2081 ms22968 KiB
#include <bits/stdc++.h> #include "roads.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define ALL(v) (v).begin(), (v).end() #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng(1); ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;} ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return mask & (-mask);} ll pop_cnt(ll mask){return __builtin_popcountll(mask);} ll ctz(ll mask){return __builtin_ctzll(mask);} ll clz(ll mask){return __builtin_clzll(mask);} ll logOf(ll mask){return 63 - clz(mask);} template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b){a = b; return true;} return false; } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b){a = b; return true;} return false; } template <class T> void printArr(T a, string separator = " ", string finish = "\n", ostream& out = cout){ for(auto i: a) out << i << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 1e5 + 69; const ll INF = 1e18 + 69; int n, k; vector<pair<int, int>> graph[N]; ll dp[N][2]; void go(int u, int p){ dp[u][0] = dp[u][1] = 0; vector<ll> diff; for(pair<int, int> v: graph[u]) if (v.first != p){ go(v.first, u); dp[u][0] += dp[v.first][0]; dp[u][1] += dp[v.first][0]; diff.push_back(dp[v.first][1] + v.second - dp[v.first][0]); } sort(ALL(diff)); for(int i = 0; i< diff.size(); ++i){ if (diff[i] >= 0 && diff.size() - i <= k) break; dp[u][1] += diff[i]; } for(int i = 0; i< diff.size(); ++i){ if (diff[i] >= 0 && diff.size() - i < k) break; dp[u][0] += diff[i]; } } vector<ll> minimum_closure_costs(int _n, vector<int> U, vector<int> V, vector<int> W) { n = _n; for(int i= 0; i<U.size(); ++i){ int u = U[i], v = V[i], w = W[i]; graph[u].push_back({v, w}); graph[v].push_back({u, w}); } vector<ll> ans(n); for(int i: W) ans[0] += i; for(int i = 1; i<n; ++i){ k = i; go(0, 0); ans[i] = dp[0][1]; } return ans; } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // int n; cin >> n; // vector<int> U, V, W; // for(int i = 1; i<n; ++i){ // int u, v, w; cin >> u >> v >> w; // U.push_back(u); V.push_back(v); W.push_back(w); // } // vector<ll> ans = minimum_closure_costs(n, U, V, W); // printArr(ans); // return 0; // }

Compilation message (stderr)

roads.cpp: In function 'void go(int, int)':
roads.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0; i< diff.size(); ++i){
      |                    ~^~~~~~~~~~~~~
roads.cpp:64:45: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |         if (diff[i] >= 0 && diff.size() - i <= k) break;
      |                             ~~~~~~~~~~~~~~~~^~~~
roads.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0; i< diff.size(); ++i){
      |                    ~^~~~~~~~~~~~~
roads.cpp:68:45: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |         if (diff[i] >= 0 && diff.size() - i < k) break;
      |                             ~~~~~~~~~~~~~~~~^~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i= 0; i<U.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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...