官方题解: If you choose any n - 1 roads then price of reducing overall dissatisfaction is equal to min(c1, c2, ..cn - 1) where сi is price of reducing by 1 dissatisfaction of i-th edge. So the best solution is to choose one edge and reduce dissatisfactio…
F - Drivers Dissatisfaction 题目大意:给你n个点,m条边,每个边都有一个权重w,每条边也有一个c表示,消耗c元可以把这条边的权重减1,求最多消耗s元的最小生成树. 思路:因为一条边的权重没有下限所以s元肯定是用在一条边上的. 那么我们先跑一个最小生成树,把这棵最小生成树建出来,然后我们枚举用了 s元之后的边,如果这条边不在树上那么加上这条边之后肯定形成了一个环,最优的方案肯定是删掉这个环中权值最大的边再次变成一棵树. 对于边(u,v)来说,如果把这条边加上,那么删掉的…
http://codeforces.com/contest/733/problem/F 题意:给你一些城市和一些路,每条路有不满意程度和每减少一点不满意程度的花费,给出最大花费,要求找出花费小于s的最小生成树中最小的不满意程度 题解:首先明确的是肯定只删除一条路然后其他的找最小生成树即可,但是直接搞复杂度O(m*mlogm)所以先prim扣出一颗最小生成树,然后枚举所有边删这条边,如果在最小生成树上,直接减到贡献即可,如果不在最小生成树上,那么加上这条边,树肯定有环了,我们用lca暴力的扣出这个…
题意:给一张n个点m条边的连通图,每条边(ai,bi)有一个权值wi和费用ci, 表示这条边每降低1的权值需要ci的花费.现在一共有S费用可以用来降低某些边的权值 (可以降到负数),求图中的一棵权值和最小的生成树并输出方案 显然是找到一条边然后将这条边减到最小 先跑一边最小生成树,找到树上最小的一点,然后在枚举其他的边, 加上这条边会产生一个环,所以需要删除这个环上面权值最大的边 这个通过类似于LCA倍增的手法做到, #include <cstdio> #include <cstring…
题目:一个带权连通无向图,给第i条边权值减1需要花费ci元,你一共有S元,求最小生成树. 容易得出钱全部花在一条边上是最优的. 我们先做一遍最小生成树. 然后我们枚举减哪一条边. 如果这条边是树上的,那么直接得出答案. 如果不是,我们可以用这一条边去替换u[i].v[i]路径之间任意一条.所以我们用倍增(我sb了用的树链剖分)找到路径上最大的那一条替换,计算答案. 最后把这条边放进树里,再求一遍最小生成树就能输出方案了. #include<cstdio> #include<cstring…
F. Drivers Dissatisfaction time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output In one kingdom there are n cities and m two-way roads. Each road connects a pair of cities, and for each road we…
Drivers Dissatisfaction time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output In one kingdom there are n cities and m two-way roads. Each road connects a pair of cities, and for each road we kno…
A: 思路: 水题,没啥意思; B: 思路: 暴力,也没啥意思; C: 思路: 思维,可以发现从前往后和为b[i]的分成一块,然后这一块里面如果都相同就没法开始吃,然后再暴力找到那个最大的且能一开始就开吃的那个怪物,然后就开始吃就好了; 话说那个医生居然等怪物吃完了才开始治疗,啧啧啧; D: 思路: mp+pair,把长方体的这些面用mp存起来,下次用的时候找一下就好了; F: 思路: 最小生成树+倍增lca求瓶颈路;贪心发现,最优情况是在一条边上使用s,求完最小生成树后枚举边,然后转换化有根树…
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://codeforces.com/contest/985/problem/F Description You are given a string s of length n consisting of lowercase English letters. For two given strings s an…
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Description You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in…