#K85957. Maintaining a Network under Capacity Constraints

    ID: 36756 Type: Default 1000ms 256MiB

Maintaining a Network under Capacity Constraints

Maintaining a Network under Capacity Constraints

You are given a network with n servers and m bidirectional connections. Each connection between two servers u and v has a capacity c. Among these servers, exactly t servers are kept active, and each active server u has a maximum load limit \(L_u\). For every connection connecting two active servers, the contribution to the load on each endpoint is defined as \(\min(c, L_u, L_v)\). Your task is to determine whether it is possible to maintain a fully connected network among the active servers such that the sum of the contributions from incident connections on any active server does not exceed its maximum load.

Note: The active part of the network is considered connected if, starting from any active server, every other active server is reachable via active connections.

inputFormat

The input is read from standard input (stdin) and consists of multiple lines:

  1. The first line contains three integers separated by spaces: \(n\) (total number of servers), \(m\) (number of connections), and \(t\) (number of active servers).
  2. The next \(m\) lines each contain three integers \(u\), \(v\) and \(c\), representing a bidirectional connection between servers \(u\) and \(v\) with capacity \(c\).
  3. The following line contains \(t\) integers indicating the IDs of the active servers.
  4. The last line contains \(t\) integers representing the maximum load \(L\) for each active server in the same order as above.

outputFormat

Print a single line to standard output (stdout) containing either "YES" if it is possible to maintain the network under the given constraints, or "NO" otherwise.

## sample
4 4 3
1 2 5
2 3 10
3 4 8
4 1 6
1 2 3
10 20 15
YES