Destroying Roads
题目链接
分析
又是变形了的最短路
我们可以考虑哪些道路必须被保留
然后枚举两个起点到终点重复的道路
考虑公合法用这些道路就可以了
\(Code\)
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
const int N = 3005;
int n , m , s1 , t1 , l1 , s2 , t2 , l2;
int tot , h[N] , dis[N][N] , vis[N];
struct edge{int to , nxt;}e[2 * N];
struct node{
int id , d;
bool operator < (node c) const {return d > c.d;}
};
priority_queue<node> Q;
inline void add(int x , int y){e[++tot] = edge{y , h[x]} , h[x] = tot;}
void dijkstra(int s)
{
while (!Q.empty()) Q.pop();
memset(vis , 0 , sizeof vis);
Q.push(node{s , dis[s][s] = 0});
while (!Q.empty())
{
node now = Q.top(); Q.pop();
int u = now.id;
if (vis[u]) continue;
vis[u] = 1;
for(register int i = h[u]; i; i = e[i].nxt)
{
int v = e[i].to;
if (dis[s][u] + 1 < dis[s][v])
{
dis[s][v] = dis[s][u] + 1;
Q.push(node{v , dis[s][v]});
}
}
}
}
int main()
{
scanf("%d%d" , &n , &m);
int x , y;
for(register int i = 1; i <= m; i++)
scanf("%d%d" , &x , &y) , add(x , y) , add(y , x);
scanf("%d%d%d%d%d%d" , &s1 , &t1 , &l1 , &s2 , &t2 , &l2);
memset(dis , 0x3f3f3f3f , sizeof dis);
for(register int i = 1; i <= n; i++) dijkstra(i);
if (dis[s1][t1] > l1 || dis[s2][t2] > l2)
{
printf("-1");
return 0;
}
int ans = dis[s1][t1] + dis[s2][t2];
for(register int i = 1; i <= n; i++)
for(register int j = 1; j <= n; j++)
{
x = dis[s1][i] + dis[i][j] + dis[j][t1];
y = dis[s2][i] + dis[i][j] + dis[j][t2];
if (x <= l1 && y <= l2)
ans = min(ans , x + y - dis[i][j]);
y = dis[t2][i] + dis[i][j] + dis[j][s2];
if (x <= l1 && y <= l2)
ans = min(ans , x + y - dis[i][j]);
}
printf("%d" , m - ans);
}
Destroying Roads的更多相关文章
- CF Destroying Roads (最短路)
Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路
题目链接: 题目 D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces 543.B Destroying Roads
B. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #302 (Div. 1) B - Destroying Roads
B - Destroying Roads 思路:这么菜的题我居然想了40分钟... n^2枚举两个交汇点,点与点之间肯定都跑最短路,取最小值. #include<bits/stdc++.h> ...
- Codeforces Round #302 (Div. 2) D - Destroying Roads 图论,最短路
D - Destroying Roads Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544 ...
- [CF544] D. Destroying Roads
D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- B. Destroying Roads
Destroying Roads 题目链接 题意 n个点,m条边每两个点之间不会有两个相同的边,然后给你两个起s1,s2和终点t1,t2; 求删除最多的边后满足两个s1到t1距离\(<=l1\) ...
- Codeforces 543B Destroying Roads(最短路)
题意: 给定一个n个点(n<=3000)所有边长为1的图,求最多可以删掉多少条边后,图满足s1到t1的距离小于l1,s2到t2的距离小于l2. Solution: 首先可以分两种情况讨论: 1: ...
- Codeforces543 B. Destroying Roads
传送门:>Here< 题意:给出一张无向图(边权为1),并给出两对起点和终点以及距离:s1,t1,l1; s2,t2,l2; 要求删除尽量多的边,使得dis(s1,t1)<=l1, ...
- [CodeForces] 543B Destroying Roads
脑洞+暴力. 因为边权是1,所以bfs一下,O(n^2)求任意两点间最短路,再枚举. ans最大是\(dis_{s1,t1}+dis_{s2,t2}\) 再考虑有公共边的情况,一定存在两个点 u, v ...
随机推荐
- 如何发布一个 TypeScript 编写的 npm 包
前言 在这篇文章中,我们将使用TypeScript和Jest从头开始构建和发布一个NPM包. 我们将初始化一个项目,设置TypeScript,用Jest编写测试,并将其发布到NPM. 项目 我们的库称 ...
- 关于Qt的QPixmap中不支持jpg文件格式的问题
问题 Qt部分版本存在不支持jpg,JPEG等图像格式的问题 qDebug()<<QImageWriter::supportedImageFormats(); 这行代码可以查看所支持的图像 ...
- 同时容器,k8s和docker区别是什么? 如何简单理解k8s和docker
1.k8s是一个开源的容器集群管理系统,可以实现容器集群的自动化部署.自动扩缩容.维护等功能. 2.Docker是一个开源的应用容器引擎,开发者可以打包他们的应用及依赖到一个可移植的容器中,发布到流行 ...
- python解释器下载与基本使用
python介绍与解释器下载基本使用 1.python发展方向 web方向.自动化运维.自动化测试.自动化办公.网络爬虫.金融量化.人工智能.机器学习.数据分析 2.python解释器 历史 ...
- 分支路径图调度框架在 vivo 效果广告业务的落地实践
作者:vivo 互联网AI团队- Liu Zuocheng.Zhou Baojian 本文根据周保建老师在"2022 vivo开发者大会"现场演讲内容整理而成.公众号回复[2022 ...
- Kali Win-KeX SL
内容: 概述 先决条件 用法 开始 声音支持 多屏支持 停止 概述 无缝模式下的 Win-KeX 将在 Windows 桌面的屏幕顶部启动 Kali Linux 面板. 通过面板启动的应用程序将与 M ...
- Typora + PicGo + B2 Cloud Storage 实现个人免费图床
前言 22年底终于购入了Typora,想着之前使用时候的痛点就是在图片管理这一块. 我尝试过使用在线的图床工具进行图片上传再将链接放入Typora,但说实话非常麻烦. 也尝试过就将图片保存在本地,但当 ...
- Codeforces Round #569 (Div. 2)
题解 Codeforces Round #569 (Div. 2) rank:1306/11165 rate: +43 1424 → 1467 Codeforces Round #569 (Div. ...
- linux 基础(2) 文件权限及其修改
文件的权限属性 在 linux 中,每个文件都有唯一的"所属者"(user)和"所属群组"(group).owner 和 group 都对文件有特殊的权限 输入 ...
- github下载后的文件,winrar打开中文是乱码
是因为编码问题,通过7Z解压后正常