A9950 | Destroying Roads
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 either from city $a$ to city $b$ , or from city $b$ to city $a$ . The road network is such that from any city you can get to any other one by moving along the roads.
You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city $s_{1}$ to city $t_{1}$ in at most $l_{1}$ hours and get from city $s_{2}$ to city $t_{2}$ in at most $l_{2}$ hours.
Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.
You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city $s_{1}$ to city $t_{1}$ in at most $l_{1}$ hours and get from city $s_{2}$ to city $t_{2}$ in at most $l_{2}$ hours.
Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.
输入格式
The first line contains two integers $n$ , $m$ ( $1<=n<=3000$ , ) — the number of cities and roads in the country, respectively.
Next $m$ lines contain the descriptions of the roads as pairs of integers $a_{i}$ , $b_{i}$ ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ ). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.
The last two lines contains three integers each, $s_{1}$ , $t_{1}$ , $l_{1}$ and $s_{2}$ , $t_{2}$ , $l_{2}$ , respectively ( $1<=s_{i},t_{i}<=n$ , $0<=l_{i}<=n$ ).
Next $m$ lines contain the descriptions of the roads as pairs of integers $a_{i}$ , $b_{i}$ ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ ). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.
The last two lines contains three integers each, $s_{1}$ , $t_{1}$ , $l_{1}$ and $s_{2}$ , $t_{2}$ , $l_{2}$ , respectively ( $1<=s_{i},t_{i}<=n$ , $0<=l_{i}<=n$ ).
输出格式
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
输入输出样例
输入 #1
5 4 1 2 2 3 3 4 4 5 1 3 2 3 5 2
输出 #1
0
输入 #2
5 4 1 2 2 3 3 4 4 5 1 3 2 2 4 2
输出 #2
1
输入 #3
5 4 1 2 2 3 3 4 4 5 1 3 2 3 5 1
输出 #3
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted