#P5295. Acyclic Edge Coloring

    ID: 18528 Type: Default 1000ms 256MiB

Acyclic Edge Coloring

Acyclic Edge Coloring

In this problem, you are given an undirected graph with n vertices and m edges. Your task is to determine if it is possible to color each edge either white or black such that the subgraph formed by white edges contains no cycle and the subgraph formed by black edges contains no cycle.

Equivalently, you need to decide whether you can partition the set of edges into two sets, each of which forms a forest. In any forest of a connected component with v vertices, the maximum number of edges is v-1. Thus, if a connected component has v vertices and e edges, then a necessary and sufficient condition for the existence of such a coloring is that e \le 2(v-1). Note that if the graph has multiple connected components, this condition must hold for each component.

You are given the values of n, m, and the list of edges. Output Yes if such a coloring is possible, and No otherwise.

The conditions can be summarized in the inequality:

[ e \le 2(v-1) \quad \text{for each connected component,} ]

where v is the number of vertices in the component and e is the number of edges in that component.

inputFormat

The first line contains two integers n and m — the number of vertices and edges of the graph.

The following m lines each contain two integers u and v representing an undirected edge connecting vertices u and v. The vertices are numbered from 1 to n.

outputFormat

Output a single line containing Yes if it is possible to color the edges as required, or No otherwise.

sample

3 3
1 2
2 3
1 3
Yes

</p>