Code:

#include <bits/stdc++.h>
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 3002
using namespace std;
queue<int>Q;
vector<int>G[maxn];
int n,m,s1,t1,l1,s2,t2,l2;
int vis[maxn],d[maxn][maxn];
void bfs(int s) {
memset(vis,0,sizeof(vis));
d[s][s]=0,vis[s]=1,Q.push(s);
while(!Q.empty()) {
int u=Q.front(); Q.pop();
for(int i=0;i<G[u].size();++i) {
int v=G[u][i];
if(!vis[v]) {
vis[v]=1,d[s][v]=d[s][u]+1;
Q.push(v);
}
}
}
}
int main() {
// setIO("input");
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i) {
int a,b;
scanf("%d%d",&a,&b);
G[a].push_back(b), G[b].push_back(a);
}
memset(d,0x3f,sizeof(d));
for(int i=1;i<=n;++i) d[i][i]=0;
for(int i=1;i<=n;++i) bfs(i);
scanf("%d%d%d%d%d%d",&s1,&t1,&l1,&s2,&t2,&l2);
if(d[s1][t1] > l1 || d[s2][t2] > l2) printf("-1\n");
else {
int ans=d[s1][t1] + d[s2][t2];
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j) {
if(d[s1][i]+d[i][j]+d[j][t1]<=l1 && d[s2][i]+d[i][j]+d[j][t2]<=l2)
{
ans=min(ans, d[s1][i]+d[s2][i]+d[i][j]+d[j][t1]+d[j][t2]);
}
}
swap(s1,t1);
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j) {
if(d[s1][i]+d[i][j]+d[j][t1]<=l1 && d[s2][i]+d[i][j]+d[j][t2]<=l2)
{
ans=min(ans, d[s1][i]+d[s2][i]+d[i][j]+d[j][t1]+d[j][t2]);
}
}
printf("%d\n",m-ans);
}
return 0;
}

  

CF543B Destroying Roads 枚举 + 思维 + BFS的更多相关文章

  1. CF543B Destroying Roads 题解

    看到没有题解就贡献一波呗 分析: 这题其实就是想让我们求一个图中两条最短路的最短(好把更多的边删掉). 我们先考虑一条最短路,别问我我怎么会的显然,就是s和t跑个最短路再用n-就行. 然后就是两条喽! ...

  2. Codeforces 543.B Destroying Roads

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

  3. B. Destroying Roads

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

  4. CF Destroying Roads (最短路)

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

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

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

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

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

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

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

  8. [CF544] D. Destroying Roads

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

  9. 危险系数(枚举点+bfs)--------蓝桥备战系列

    标题:危险系数 抗日战争时期,冀中平原的地道战曾发挥重要作用. 地道的多个站点间有通道连接,形成了庞大的网络.但也有隐患,当敌人发现了某个站点后,其它站点间可能因此会失去联系.        我们来定 ...

随机推荐

  1. Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib 的一种情形

    没有引用任何.net 4.5的东西,也没有引用 Newtonsoft.dll,原因是引用了微软的tlb类型库,引用方法如 https://www.cnblogs.com/nanfei/p/108798 ...

  2. 【MM系列】SAP MM模块-分析采购收货完成标识

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-分析采购收货完成标 ...

  3. nginx+memcached缓存图片

    1.nginx的配置如下: location ^~ /images/ {     set $memcached_key  "$uri"; #用URI作为key去memcached中 ...

  4. 关于BeautifulSoup4 解析器的说明

    一.解析器概述 如同前几章笔记,当我们输入: soup=BeautifulSoup(response.body) 对网页进行析取时,并未规定解析器,此时使用的是python内部默认的解析器“html. ...

  5. Golang中的error类型

    Golang中的error类型 error类型本身就是一个预定义好的接口,里面定义了一个method type error interface { Error() string } 生成一个新的err ...

  6. python+selenium下弹窗alter对象处理01

    alt.accept() :                            等同于单击“确认”或者“OK” alt.dismiss() :                            ...

  7. js for 循环

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. [知乎]ARM 到底是什么

    [小宅按]近期公司推出来基于ARM芯片的服务器,本文就一些基本概念,比如ARM, ARM64, ARMv8, ARM7,ARMv7, 64位等让人费解的概念进行了粗浅地分析,涉及的关键字已用粗体标出. ...

  9. fidder抓包工具使用方法,完整流程

    fidder抓包工具使用方法,完整流程 https://blog.csdn.net/lw545034502/article/details/82150779 版权声明:本文为博主原创文章,遵循 CC ...

  10. P1067多项式输出

    这道题是2009普及组的题,仍然是一个字符串+模拟.(蒻到先不刷算法) 这道题的题干给了很多的提示,也很全面,但是当我把种种情况都考虑到了后,在写代码的过程中仍然出现了很多的错误,wa了三四次.其实导 ...