#K69982. Facility Placement
Facility Placement
Facility Placement
You are given N cities and M bidirectional roads. Each road is represented by three integers u, v, and w, where u and v are the connected cities and w is a weight (which is not used in the facility placement decision). You are also given an integer K representing the number of facilities you can place. Your task is to determine whether it is possible to choose K cities to place facilities such that every city either has a facility or is adjacent (directly connected by a road) to a city with a facility.
If it is possible, output "YES" followed by a list of K distinct city numbers where facilities are placed. Otherwise, output "NO".
The problem can be formulated mathematically as follows: Given an undirected graph G = (V, E) with |V| = N and a positive integer K, decide if there exists a subset S ⊆ V with |S| = K such that for every vertex v ∈ V, either v ∈ S or ∃ u ∈ S such that (u,v) ∈ E.
Note: If K ≥ N, you can trivially place a facility in every city.
inputFormat
The first line of input contains three integers N, M, and K separated by spaces.
Then M lines follow, each containing three integers u, v, and w — representing a road between cities u and v with weight w.
If M is 0, then no road description follows.
outputFormat
If it is possible to cover all the cities with the given facilities, print "YES" on the first line and on the second line print K space-separated integers denoting the cities where the facilities are placed. If there are multiple valid answers, output any of them.
If it is not possible, simply print "NO".
## sample5 4 2
1 2 3
2 3 2
3 4 4
4 5 1
YES
1 2
</p>