A8673 | Flights
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
LiLand is a country, consisting of $n$ cities. The cities are numbered from 1 to $n$ . The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the flights are arranged in a way that once you leave a city you will never be able to return to that city again.
Previously each flight took exactly one hour, but recently Lily has become the new manager of transportation system and she wants to change the duration of some flights. Specifically, she wants to change the duration of some flights to exactly 2 hours in such a way that all trips from city 1 to city $n$ take the same time regardless of their path.
Your task is to help Lily to change the duration of flights.
Previously each flight took exactly one hour, but recently Lily has become the new manager of transportation system and she wants to change the duration of some flights. Specifically, she wants to change the duration of some flights to exactly 2 hours in such a way that all trips from city 1 to city $n$ take the same time regardless of their path.
Your task is to help Lily to change the duration of flights.
输入格式
First line of the input contains two integer numbers $n$ and $m$ $(2<=n<=1000; 1<=m<=5000)$ specifying the number of cities and the number of flights.
Each of the next $m$ lines contains two integers $a_{i}$ and $b_{i}$ $(1<=a_{i}<b_{i}<=n)$ specifying a one-directional flight from city $a_{i}$ to city $b_{i}$ . It is guaranteed that there exists a way to travel from city number 1 to city number $n$ using the given flights. It is guaranteed that there is no sequence of flights that forms a cyclical path and no two flights are between the same pair of cities.
Each of the next $m$ lines contains two integers $a_{i}$ and $b_{i}$ $(1<=a_{i}<b_{i}<=n)$ specifying a one-directional flight from city $a_{i}$ to city $b_{i}$ . It is guaranteed that there exists a way to travel from city number 1 to city number $n$ using the given flights. It is guaranteed that there is no sequence of flights that forms a cyclical path and no two flights are between the same pair of cities.
输出格式
If it is impossible for Lily to do her task, print "No" (without quotes) on the only line of the output.
Otherwise print "Yes" (without quotes) on the first line of output, then print an integer $ans_{i}$ $(1<=ans_{i}<=2)$ to each of the next $m$ lines being the duration of flights in new transportation system. You should print these numbers in the order that flights are given in the input.
If there are multiple solutions for the input, output any of them.
Otherwise print "Yes" (without quotes) on the first line of output, then print an integer $ans_{i}$ $(1<=ans_{i}<=2)$ to each of the next $m$ lines being the duration of flights in new transportation system. You should print these numbers in the order that flights are given in the input.
If there are multiple solutions for the input, output any of them.
输入输出样例
输入 #1
3 3 1 2 2 3 1 3
输出 #1
Yes 1 1 2
输入 #2
4 4 1 2 2 3 3 4 1 4
输出 #2
No
输入 #3
5 6 1 2 2 3 3 5 1 4 4 5 1 3
输出 #3
Yes 1 1 1 2 1 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted