题目链接

\(Destroying\)

分析

又是变形了的最短路

我们可以考虑哪些道路必须被保留

然后枚举两个起点到终点重复的道路

考虑公合法用这些道路就可以了

\(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的更多相关文章

  1. CF Destroying Roads (最短路)

    Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路

    题目链接: 题目 D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces 543.B Destroying Roads

    B. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #302 (Div. 1) B - Destroying Roads

    B - Destroying Roads 思路:这么菜的题我居然想了40分钟... n^2枚举两个交汇点,点与点之间肯定都跑最短路,取最小值. #include<bits/stdc++.h> ...

  5. Codeforces Round #302 (Div. 2) D - Destroying Roads 图论,最短路

    D - Destroying Roads Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544 ...

  6. [CF544] D. Destroying Roads

    D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. B. Destroying Roads

    Destroying Roads 题目链接 题意 n个点,m条边每两个点之间不会有两个相同的边,然后给你两个起s1,s2和终点t1,t2; 求删除最多的边后满足两个s1到t1距离\(<=l1\) ...

  8. Codeforces 543B Destroying Roads(最短路)

    题意: 给定一个n个点(n<=3000)所有边长为1的图,求最多可以删掉多少条边后,图满足s1到t1的距离小于l1,s2到t2的距离小于l2. Solution: 首先可以分两种情况讨论: 1: ...

  9. Codeforces543 B. Destroying Roads

    传送门:>Here< 题意:给出一张无向图(边权为1),并给出两对起点和终点以及距离:s1,t1,l1; s2,t2,l2; 要求删除尽量多的边,使得dis(s1,t1)<=l1, ...

  10. [CodeForces] 543B Destroying Roads

    脑洞+暴力. 因为边权是1,所以bfs一下,O(n^2)求任意两点间最短路,再枚举. ans最大是\(dis_{s1,t1}+dis_{s2,t2}\) 再考虑有公共边的情况,一定存在两个点 u, v ...

随机推荐

  1. 更换linux的开机启动图片, 启动主题

    简述 之前就想更改开机的启动图片,但是后来简单查了一下,说要重新编译内核,听到编译我就望而却步了,今天发现只是个命令而已,注意这里我用的是 linux mint .这里更改不是 grub 主题, 是 ...

  2. 使用Python实现多线程、多进程、异步IO的socket通信

    多线程实现socket通信服务器端代码 import socket import threading class MyServer(object): def __init__(self): # 初始化 ...

  3. SQL语句查询关键字前期数据准备

    前期数据准备 create table emp( id int primary key auto_increment, name varchar(20) not null, gender enum(' ...

  4. 2.5:Python常用内置数据结构、多维数组ndarray、Series和DataFrame

    一.Python内置数据结构 1.赋值生成列表 la=[1,2,3,4] la 2.强制转换为列表 lb=list("Hello") lb 3.推导式生成列表 s="ab ...

  5. 【大数据-课程】高途-天翼云侯圣文-Day2:离线数仓搭建分解

    一.内容介绍 昨日福利:大数据反杀熟 今日:数据看板 离线分析及DW数据仓库 明日:实时计算框架及全流程 一.数仓定义及演进史 1.概念 生活中解答 2.数据仓库的理解 对比商品仓库 3.数仓分层内容 ...

  6. 【Java EE】Day06 JDBC连接池介绍、C3P0连接池实现、Druid连接池实现、JDBCTemplate

    一.数据库连接池介绍 1.引入 之前:每次都要获取连接释放连接 现在:连接重复使用 2.概念: 存放数据库连接的容器 3.实现 DataSource接口 三种实现 标准实现 连接池实现 C3P0 Dr ...

  7. go-carbon 1.5.1 版本发布, 修复已知 bug 和新增土耳其翻译文件

    carbon 是一个轻量级.语义化.对开发者友好的golang时间处理库,支持链式调用. 目前已被 awesome-go 收录,如果您觉得不错,请给个star吧 github.com/golang-m ...

  8. 论文翻译:2022_DNS_1th:Multi-scale temporal frequency convolutional network with axial attention for speech enhancement

    论文地址:带轴向注意的多尺度时域频率卷积网络语音增强 论文代码:https://github.com/echocatzh/MTFAA-Net 引用:Zhang G, Yu L, Wang C, et ...

  9. Dubbo 3 之 Triple 流控反压原理解析

    作者:顾欣 Triple 是 Dubbo 3 提出的基于 HTTP2 的开放协议, 旨在解决 Dubbo 2 私有协议带来的互通性问题. Triple 基于 HTTP/2 定制自己的流控,支持通过特定 ...

  10. 小型web产品的功能测试要点或测试大纲

    本文参考配置啦:-- Web类产品功能测试大纲,黑盒测试参考测试范围 [官网]:无 应用场景 黑盒测试,功能测试中常常需要考虑很多问题,这里根据本人的工作经验遇到的进行了系列总结.给出了一个常用的测试 ...