Codeforces 543B Destroying Roads(最短路)】的更多相关文章

题意: 给定一个n个点(n<=3000)所有边长为1的图,求最多可以删掉多少条边后,图满足s1到t1的距离小于l1,s2到t2的距离小于l2. Solution: 首先可以分两种情况讨论: 1:假设最后留下的边是互不相交的两条路径.此时的答案是n-s1到t1的最短路径-s2到t2的最短路径. 2:假设最后留下的边有重合的一段,此时只要枚举重合的这一段的起点和终点,就可以判断.注意此时要考虑这两条路径经过枚举的两点的顺序. 限制的条件比较多,可以用来剪枝的条件也很多. 由于所有边的长度为1,用DF…
脑洞+暴力. 因为边权是1,所以bfs一下,O(n^2)求任意两点间最短路,再枚举. ans最大是\(dis_{s1,t1}+dis_{s2,t2}\) 再考虑有公共边的情况,一定存在两个点 u, v ,最后留下的边为(s1,u),(s2,u),(u,v),(v,t1),(v,t2)或是 (s1,u),(t2,u),(u,v),(v,t1),(v,s2) 五组点之间最短路. 如图: 因此代码如下. #include <iostream> #include <cstdio> #inc…
题目链接: 题目 D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes inputstandard input outputstandard output 问题描述 In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbe…
Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with intege…
题目:有n个城镇,m条边权为1的双向边让你破坏最多的道路,使得从s1到t1,从s2到t2的距离分别不超过d1和d2. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <stack> #in…
D - Destroying Roads Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/problem/D Description In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers f…
B. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with int…
B - Destroying Roads 思路:这么菜的题我居然想了40分钟... n^2枚举两个交汇点,点与点之间肯定都跑最短路,取最小值. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsk…
D. Destroying Roads 题目大意: In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road…
Destroying Roads 题目链接 题意 n个点,m条边每两个点之间不会有两个相同的边,然后给你两个起s1,s2和终点t1,t2; 求删除最多的边后满足两个s1到t1距离\(<=l1\),s2到t2的距离\(<=l2\) 求能删除最多的边. 思路 先bfs求出每两个点之间的最短路,然后暴力枚举两条路径的重合路径,枚举时有两种组合,$$(s1,s2)(t1,t2)||(s1,t2)(s2,t1)$$ 枚举的重合路径为[i][j],所以可以删除的边为总的边数减去满足两个条件所要求的最小边数…