P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There a…
P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There a…
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例 输出样例 说明 思路 AC代码 题面 题目链接 P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of…
题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There are N (1 ≤ N ≤ 1,000) forlorn telephon…
P1948 [USACO08JAN]电话线Telephone Lines 题意 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. Ther…
思路 考虑题目要求求出最小的第k+1大的边权,想到二分答案 然后二分第k+1大的边权wx 把所有边权<=wx的边权变为0,边权>wx的边权变为0,找出最短路之后,如果dis[T]<=k,则答案可行,反之则不可行 似乎有dp解法的样子,真神奇 代码 #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; in…
传送门 思路: 二分+最短路径:可以将长度小于等于 mid 的边视为长度为 0 的边,大于 mid 的边视为长度为 1 的边,最后用 dijkstra 检查 d [ n ] 是否小于等于 k 即可. 标程: #include<cstring> #include<queue> #include<cstdio> #include<iostream> #include<vector> #include<fstream> #include&l…
多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人.该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话线杆,任意两根线杆之间没有电话线连接,一共有p(1<=p<=10000)对电话杆可以拉电话线.其他的由于地震使得无法连接. 第i对电线杆的两个端点分别是ai,bi,它们的距离为li(1<=li<=1000000).数据中每对(ai,bi)只出现一次.编号为1的电话杆已经接入了全国的电话网络,整个…
题面 题解 很显然,答案满足单调性. 因此,可以使用二分答案求解. 考虑\(check\)的实现. 贪心地想,免费的\(k\)对电话线一定都要用上. 每次\(check\)时将小于\(mid\)的边权设为\(0\),其它的设为\(1\). 跑一边最短路判断\(\mathrm{dist[n]}\)是否\(\leq k\)即可. 代码 #include <bits/stdc++.h> #define itn int #define gI gi using namespace std; inline…
这道题其实是分层图,但和裸的分层图不太一样.因为它只要求路径总权值为路径上最大一条路径的权值,但仔细考虑,这同时也满足一个贪心的性质,那就是当你每次用路径总权值小的方案来更新,那么可以保证新的路径权值尽量小. 所以这道题在不删边的情况下可以使用Dij来跑,而删边权的情况就是分层图. 所以就拿分层图来搞好了^_^. 由于这个数据p和k都比较大,所以直接建k+1层图是要爆的,而k+1层图边都一样,我们就用dis[层数(0-k)]来表示. 具体的就是每次Dij转移是要分两种情况: 1.在原层跑,也就是…