CF60C.Mushroom Strife

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Pasha and Akim were making a forest map — the lawns were the graph's vertexes and the roads joining the lawns were its edges. They decided to encode the number of laughy mushrooms on every lawn in the following way: on every edge between two lawns they wrote two numbers, the greatest common divisor (GCD) and the least common multiple (LCM) of the number of mushrooms on these lawns. But one day Pasha and Akim had an argument about the laughy mushrooms and tore the map. Pasha was left with just some part of it, containing only m roads. Your task is to help Pasha — use the map he has to restore the number of mushrooms on every lawn. As the result is not necessarily unique, help Pasha to restore any one or report that such arrangement of mushrooms does not exist. It is guaranteed that the numbers on the roads on the initial map were no less that 1 and did not exceed 106.

帕沙和阿金正在绘制一片森林的地图——草坪是图的顶点,连接草坪的道路是图的边。他们决定以如下方式对每块草坪上的“欢笑蘑菇”数量进行编码:在连接两块草坪的每条边上,写下这两块草坪上蘑菇数量的最大公约数(GCD)和最小公倍数(LCM)。但有一天,帕沙和阿金因“欢笑蘑菇”问题发生争执,把地图撕毁了。帕沙只保留了其中一部分,仅包含 $ m $ 条道路。你的任务是帮助帕沙——利用他手中残存的地图,恢复每块草坪上的蘑菇数量。由于结果不一定唯一,请帮助帕沙恢复任意一种可行方案;若不存在满足条件的方案,则报告无解。题目保证原始地图上所有道路上所写的数字均不小于 $ 1 $,且不超过 $ 10^6 $。

输入格式

The first line contains two numbers n and m () which are the numbers of lawns and roads we know about. Each of the following m lines contains four numbers which are the numbers of lawns the road connects, the GCD and the LCM of the numbers of mushrooms on these lawns (1 ≤ GCD, LCM ≤ 106).

It is guaranteed, that no road connects lawn to itself, and no two lawns are connected by more than one road.

第一行包含两个数 nn 和 mm(),分别表示已知的草坪数量和道路数量。接下来的 mm 行中,每行包含四个数:该道路所连接的两个草坪的编号,以及这两个草坪上蘑菇数量的最大公约数(GCD)与最小公倍数(LCM)(1 ≤ GCD, LCM ≤ 1061 ≤ \text{GCD}, \text{LCM} ≤ 10^6)。

保证不存在连接同一草坪的道路,且任意两个草坪之间至多只有一条道路相连。

输出格式

The answer should contain "YES" or "NO" on the first line, saying whether it is possible or not to perform the arrangement. If the answer is "YES", print on the following line n numbers which are the numbers of mushrooms on the corresponding lawns.

第一行应输出“YES”或“NO”,表示是否可能完成该安排。如果答案为“YES”,则在下一行输出 n 个数字,分别表示对应草坪上的蘑菇数量。

输入输出样例

  • 输入#1

    1 0

    输出#1

    YES
    1
  • 输入#2

    2 1
    1 2 1 3

    输出#2

    YES
    1 3
  • 输入#3

    3 2
    3 2 1 2
    3 1 1 10

    输出#3

    YES
    5 1 2
  • 输入#4

    2 1
    1 2 3 7

    输出#4

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页