CF241E.Flights
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
LiLand 是一个由 n 座城市组成的国家,城市编号为 1 到 n。该国以一种极为特殊的交通系统而闻名:城市之间存在大量单向航班,使得城市间可以通行;但这些航班的安排方式十分特殊——一旦离开某座城市,便永远无法再返回该城市。
此前,每趟航班的飞行时间恰好为 1 小时;但最近,Lily 成为了该交通系统的新任管理者,她希望调整部分航班的飞行时间,使其恰好变为 2 小时,从而保证:从城市 1 到城市 n 的所有路径的总耗时均相等。
你的任务是帮助 Lily 调整航班的飞行时间。
输入格式
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.
输入的第一行包含两个整数 n 和 m(2 ≤ n ≤ 1000;1 ≤ m ≤ 5000),分别表示城市的数量和航班的数量。
接下来的 m 行,每行包含两个整数 ai 和 bi(1 ≤ ai < bi ≤ n),表示一条从城市 ai 到城市 bi 的单向航班。题目保证存在一条由给定航班构成的、从城市 1 到城市 n 的路径。题目还保证不存在任何形成环路的航班序列,且任意两个城市之间至多只有一条航班(即不存在两条航班连接同一对城市)。
输出格式
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.
如果莉莉无法完成她的任务,则在输出的唯一一行中打印“No”(不带引号)。
否则,在输出的第一行打印“Yes”(不带引号),然后在接下来的 m 行中,每行打印一个整数 ansi(1 ≤ ansi ≤ 2),表示新交通系统中对应航班的持续时间。这些数字应按输入中航班给出的顺序输出。
若输入存在多个解,输出其中任意一个即可。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?