ISP Merger

면접 대비

시간 제한2초메모리 제한512 MB

요약
각 서버의 소켓 수 제한이 주어진 그래프에서 간선을 k개 이하로 추가하거나 삭제해 전체를 하나로 연결할 수 있는지 판정한다.
난이도

보통10점 중 5점

유형
유니온 파인드, 그래프, 그리디
정답자
아직 제출이 없습니다

문제

A number of regional Internet Service Providers (ISPs), both big and small have recently been forced into a merger by the government, in an effort to improve service for all. Of course this has been decided without consulting you, the chief network infrastructure officer, and a deadline for when the ISPs should be merged have already been set.

You have a set of n servers, each with a limited number of network sockets that can be used for connecting physically to other servers. Some servers are already linked up in the existing network architecture, and if server 0 is linked to server 2, then 2 is also linked to server 0 (as you use full duplex ethernet Cat6 cables). No server is directly connected to itself, and no two servers are directly linked with more than one connection.

You want to connect the servers to form a single network, such that all servers can reach each other through some sequence of connections. To make the set deadline, you have estimated that you only have time to make k edits to the existing network infrastructure. An edit is either to remove an existing connection between two servers, or to add a new connection between two servers.

Can you connect all the servers to the same network using at most k edits, within the limitations on the number of network sockets in each server?

입력

The first line of the input is three space separated integers n (1 ≤ n ≤ 100 000), the number of servers, m (0 ≤ m ≤ 200 000), the number of existing connections and k (0 ≤ k ≤ 50 000), the number of edits you have time to make. Then follows a line with n integers c0, c1, . . . , ci, . . . , cn−1, with the i’th number giving the number of network sockets for the i’th server (for all i the capacity is bounded by 1 ≤ ci < n). Then m lines follow, with two integers uj and vj each, giving the id’s of two servers that are connected in the old network architecture. Servers are 0-indexed, i.e. for every j, it holds that 0 ≤ uj, vj < n. A server will never be connected to more servers than it has connection sockets.

출력

Output “yes” on a single line if the servers can be connected to one network by making k or less edits, and “no” if it is not possible.

예제3

  1. 예제 1

    입력
    4 5 2
    3 3 3 3
    0 1
    0 3
    1 3
    1 2
    2 3
    
    예상 출력
    yes
    
  2. 예제 2

    입력
    5 4 4
    1 1 2 2 2
    0 1
    2 3
    3 4
    4 2
    
    예상 출력
    yes
    
  3. 예제 3

    입력
    3 0 3
    1 1 1
    
    예상 출력
    no