atcoder#ARC106B. [ARC106B] Values
[ARC106B] Values
Score : points
Problem Statement
Given is a simple undirected graph with vertices and edges. The -th edge connects Vertex and Vertex . Initially, Vertex has the value written on it. You want to change the values on Vertex , , Vertex to , , , respectively, by doing the operation below zero or more times.
- Choose an edge, and let Vertex and Vertex be the vertices connected by that edge. Choose one of the following and do it:- Decrease the value by , and increase the value by .
- Increase the value by , and decrease the value by .
- Decrease the value by , and increase the value by .
- Increase the value by , and decrease the value by .
Determine whether it is possible to achieve the objective by properly doing the operation.
Constraints
- The given graph is simple, that is, has no self-loops and no multi-edges.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print Yes
if it is possible to achieve the objective by properly doing the operation, and No
otherwise.
3 2
1 2 3
2 2 2
1 2
2 3
Yes
You can achieve the objective by, for example, doing the operation as follows:
- In the first operation, choose the edge connecting Vertex and . Then, increase by and decrease by .
- In the second operation, choose the edge connecting Vertex and . Then, increase by and decrease by .
This sequence of operations makes , , and .
1 0
5
5
Yes
The objective may be achieved already in the beginning.
2 1
1 1
2 1
1 2
No
There is no way to do the operation to achieve the objective.
17 9
-905371741 -999219903 969314057 -989982132 -87720225 -175700172 -993990465 929461728 895449935 -999016241 782467448 -906404298 578539175 9684413 -619191091 -952046546 125053320
-440503430 -997661446 -912471383 -995879434 932992245 -928388880 -616761933 929461728 210953513 -994677396 648190629 -530944122 578539175 9684413 595786809 -952046546 125053320
2 10
6 12
9 11
11 5
7 6
3 15
3 1
1 9
10 4
Yes