381. Bidirected Graph
Time limit per test: 0.5
second(s)
Memory limit: 262144
kilobytes
input: standard
output: standard
The notion of bidirected graphs is used to formulate and solve wide range of combinatorial optimization problems: matchings,
bmatchings,
Tjoins,
Tpaths packing and so on. Bidirected graph is a generalization of directed graph, where every arc has two orientations — one for every end.
More formally, bidirected graph is a tuple (
V,
E,
ends, ω).
V is a set of nodes,
E is a set of edges,
ends is a mapping from
E:
ends(
e) = {
u,
v}, where
u,
v ∈
V,
u ≠
v. For every
e ∈
E and
v ∈
ends(
e) we define ω(
e,
v) ∈ {1, +1}. It is called the direction of the edge
e in the node
v.
An
s
t walk in a bidirected graph
G is an alternating sequence
P = (
s =
v_{0},
e_{1},
v_{1},...,
e_{k},
v_{k} =
t),
where
v_{i} ∈
V,
e_{i} ∈
E,
ends(
e_{i}) = {
v_{i  1},
v_{i}} and ω(
e_{i + 1},
v_{i}) ω(
e_{i},
v_{i}) = 1.
A directed graph without loops can be considered as bidirected, if we replace each arc
a = (
u,
v) with an edge
e_{a}, and put
ends(
e_{a}) = {
u,
v}, ω(
e_{a},
u) = 1, ω(
e_{a},
v) = +1.
An elementary transformation on node
v is defined as follows: if for
e ∈
E, ω(
e,
v) is defined, then negate it. It's clear that elementary transformations don't change the set of walks in
G.
We want to determine if it is possible to convert bidirected graph to "directed" graph (i.e. to graph that can be obtained from some directed graph by means of the consideration described above) using several elementary transformations. If it is, we also want to know how to do it using the minimal number of elementary transformations.
Input
The first line of the input contains two integer numbers
n and
m — the number of vertices and the number of edges in the graph (
,
). Next
m lines describe the edges of the graph. Each line consists of four numbers
a_{i},
b_{i},
d_{i,1},
d_{i,2}, where
a_{i} and
b_{i} are the ends of the egde
e and
d_{i,1}=ω(
e,
a_{i}),
d_{i,2}=ω(
e,
b_{i}); 1 ≤
a_{i},
b_{i} ≤
n,
d_{i,j} ∈ {1, 1}.
Output
If it is impossible to perform required transformation, output should contain exactly one string "
NO
" (quotes for clarity only). Otherwise, the first line should contain string "
YES
", the second line should contain the number of elementary transformations in your solution, and the following lines should describe those transformations. Each transformation should be described by exactly one number — the index of the vertex of this transformation. If there are several answers with the minimal number of transformations, output any of them.
Example(s)
sample input

sample output

4 3
1 3 1 1
2 3 1 1
3 4 1 1

YES
1
3

sample input

sample output

3 3
1 2 1 1
2 3 1 1
1 3 1 1

NO
