Submission #1000280

#TimeUsernameProblemLanguageResultExecution timeMemory
1000280panRoad Closures (APIO21_roads)C++17
12 / 100
613 ms55488 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define input2(x, y) scanf("%lld%lld", &x, &y); #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define all(x) x.begin(), x.end() #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define FOR(i, x, n) for (ll i =x; i<=n; ++i) #define RFOR(i, x, n) for (ll i =x; i>=n; --i) using namespace std; mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count()); //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> piii; struct balancedheap { multiset<ll> chosen, store; ll k, sum; balancedheap() {k = sum = 0;} void balance() { while (chosen.size() > k && chosen.size()) { sum -= *prev(chosen.end()); store.insert(*prev(chosen.end())); chosen.erase(prev(chosen.end())); } while (chosen.size() < k && store.size() && *store.begin() < 0) { sum += *store.begin(); chosen.insert(*store.begin()); store.erase(store.begin()); } while (chosen.size() && store.size() && *prev(chosen.end()) > *store.begin()) { ll x = *store.begin(), y = *prev(chosen.end()); sum += x - y; store.erase(store.begin()); chosen.erase(--chosen.end()); store.insert(y); chosen.insert(x); } } void insert(ll x) { store.insert(x); balance(); } void erase(ll x) { if (chosen.find(x)==chosen.end()) store.erase(store.lb(x)); else chosen.erase(chosen.lb(x)); balance(); } void setcap(ll x){k = x; balance();} }; ll const MAXN = 100005; ll n, k; set<pi> adj[MAXN]; ll vis[MAXN], dp[MAXN][2], sum[MAXN], deg[MAXN]; balancedheap hp[MAXN]; vector<pi> order; vector<ll> ans; void dfs(ll x, ll p) { vis[x] = 1; ll ans = sum[x]; vector<ll> bt; for (pi u: adj[x]) { if (u.f==p) continue; dfs(u.f, x); ans += dp[u.f][1] + u.s; ll ch = dp[u.f][0] - dp[u.f][1] - u.s; hp[x].insert(ch); bt.pb(ch); } hp[x].setcap(k-1); dp[x][0] = ans +hp[x].sum; hp[x].setcap(k); dp[x][1] = ans + hp[x].sum; for (ll u: bt) hp[x].erase(u); } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; for (ll i=0; i<n-1; ++i) { adj[U[i]].insert(mp(V[i], W[i])); adj[V[i]].insert(mp(U[i], W[i])); deg[U[i]]++; deg[V[i]]++; } for (ll i=0; i<n; ++i) order.pb(mp(deg[i], i)); sort(all(order)); ll idx = 0; ans.assign(n, 0); //show(1); for (ll j=0; j<n; ++j) { show(j); k = j; while (idx < n && order[idx].f <= k) { ll now = order[idx].s; for (pi u: adj[now]) { sum[u.f] += u.s; hp[u.f].insert(-u.s); adj[u.f].erase(mp(now, u.s)); } idx++; } for (ll i=idx; i<n; ++i) vis[order[i].s]= 0; for (ll i=idx; i<n; ++i) if (!vis[order[i].s]) { dfs(order[i].s, -1); ans[j] += dp[order[i].s][1]; } } return ans; }

Compilation message (stderr)

roads.cpp: In member function 'void balancedheap::balance()':
roads.cpp:44:24: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   44 |   while (chosen.size() > k && chosen.size())
      |          ~~~~~~~~~~~~~~^~~
roads.cpp:50:24: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   50 |   while (chosen.size() < k && store.size() && *store.begin() < 0)
      |          ~~~~~~~~~~~~~~^~~
#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...