A7994 | Mushroom Strife
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $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<=10^{6}$ ).
It is guaranteed, that no road connects lawn to itself, and no two lawns are connected by more than one road.
It is guaranteed, that no road connects lawn to itself, and no two lawns are connected by more than one road.
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted