CF1088F Ehab and a weird weight formula 题意 给定一棵树,点有点权,其中这棵树满足除了权值最小的点外,每个点至少有一个点权小于它的相邻点. 要求你重新构建这棵树,使得代价最小.计算代价的方法如下: 点的代价: \(deg_xv_x\),其中\(deg_x\)表示点\(x\)的度 边\((x, y)\)的代价:\(log_2(dis(x, y)) \cdot min(v_x, v_y)\),其中\(dis(x, y)\)表示\(x\)和\(y\)在原树中的距…
CF1088F Ehab and a weird weight formula 推性质猜结论题 第一步转化,考虑把点的贡献加到边里: $con=\sum (log_2(dis(a_u,a_b))\times min(a_u,a_v))+a_u+a_v$ 然后一个结论: 一个点最多有一个相邻的点比它小 因为会连出一串,只能在唯一的最小值点结束 所以,以最小值为根,建出有根树,每个点的fa就是比它小的 整个树越往祖先权值越小 不妨再给边定向,令边的方向就是:$a_u>a_v,a_u->a_v$,…
首先把点权归到边上,设点权较小的一个点是v,也就是(u,v)的边权是log2(dis(u,v))*a[v]+a[v]+a[u] 然后还有一个性质就是这棵树按点权最小点提起来就是一个堆 暴力是n^2的MST,然后考虑优化,按照点权从小到大加入生成树,那么每个点加进去的时候会连到点权比他小的点上 因为log2是上取整的,并且从根到一个点的链上的点权是单调递增的,所以一定是和这个点距离为2^k的点最好,所以倍增然后枚举这些点即可,注意最要要特判一下直接接在根下面的情况 #include<iostrea…
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树,满足只有一个点的权值最小,然后除开这个点,每个点都有一个权值比它更小的点与之相邻. 然后要求你重构这颗树,满足点权及边权和最小. 点权计算方法: au = au*num(num为与之相邻边的个数); 边权计算方法: e{u,v},we = dis(u,v)*min(au,av)  (dis(u,v…
[题目]D. Best Edge Weight [题意]给定n个点m条边的带边权无向连通图,对每条边求最大边权,满足其他边权不变的前提下图的任意最小生成树都经过它.n,m<=2*10^5,1<=wi<=10^9. [算法]最小生成树+倍增LCA+并查集 [题解]首先求出图的一个最小生成树M,则所有边分成树边和非树边. 一.对于非树边(u,v),假设u和v在最小生成树M上的路径的最大边权是Max.要保证这条边在最小生成树上,只要w(u,v)=Max-1. 下面证明w(u,v)=Max-1时…
先用kruskal处理出一个最小生成树 对于非树边,倍增找出两端点间的最大边权-1就是答案 对于树边,如果它能被替代,就要有一条非树边,两端点在树上的路径覆盖了这条树边,而且边权不大于这条树边 这里可以树剖来做,但是不想用.. 如果先把非树边从小到大排序然后去覆盖树边,那么一条树边只需要被覆盖一次 所以可以用一个并查集来把父子边被覆盖的点合到一起,在合并之前记下来这次覆盖的边权,下次再覆盖的时候直接跳过去就可以 #include<bits/stdc++.h> #define pa pair&l…
A. Ehab and another construction problem Water. #include <bits/stdc++.h> using namespace std; int x; int main() { while (scanf("%d", &x) != EOF) { , b = -; ; i <= x && a == - && b == -; ++i) { for (int j = i; j <=…
A:Ehab and another construction problem #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #de…
Aspects of the invention relate to improvements to the Least Recently Used (LRU) cache replacement method. Weighted LRU (WLRU) and Compact Weighted LRU (CWLRU) are CPU cache replacement methods that have superior hit rates to LRU replacement for prog…
You are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integer weight we can give to it so that it is contained…