#P7763. Achieving Complete Connectivity

    ID: 20950 Type: Default 1000ms 256MiB

Achieving Complete Connectivity

Achieving Complete Connectivity

Consider a country with \(N\) cities connected by bidirectional flight routes. An operation is defined as follows:

  • Select one city \(v\).
  • Cancel all existing flight routes incident to \(v\) and then establish a direct flight from \(v\) to every other city (i.e. add an edge from \(v\) to every \(u \neq v\)).

Two cities \(u\) and \(v\) have a direct connection if at least one of them has performed the operation after their last mutual update. In other words, if we perform the operation on every city exactly once in a suitable order, every pair of cities will end up connected by a direct flight.

Given the initial connected network of \(N\) cities and \(M\) bidirectional flight routes, determine whether there exists a sequence of operations (the number of operations is not limited) that results in every pair of different cities being connected by a direct flight. Note that if a city is never updated, its originally missing direct connections may remain missing. However, if we update every city once in some order, then for any two cities \(i, j\), the city which was updated later will guarantee a direct connection between \(i\) and \(j\).

Thus, under the assumption that the initial network is connected, such a sequence always exists.

inputFormat

The first line contains two integers \(N\) and \(M\) \((1 \leq N \leq 10^5, 0 \leq M \leq 10^5)\), where \(N\) is the number of cities and \(M\) is the number of bidirectional flight routes.

The following \(M\) lines each contain two integers \(u\) and \(v\) (\(1 \leq u,v \leq N\), \(u \neq v\)) representing an existing flight between cities \(u\) and \(v\). It is guaranteed that the initial network is connected.

outputFormat

Output a single line containing YES if there exists a sequence of operations that results in a complete flight network (i.e., every pair of distinct cities is directly connected), and NO otherwise.

Note: Under the given conditions, it can always be achieved, so the answer is always YES.

sample

3 2
1 2
2 3
YES