Under construction

Still being built. Things may change

Data Center Maintenance

Interview

Time limit1sMemory limit1024 MB

Summary
Given data center maintenance hours and client pairs, find the fewest data centers to shift one hour later so every client keeps one copy reachable.
Level

Medium6 of 10

Topics
Graph, DFS, Implementation
Solved
No attempts yet

Statement

BigData Inc. operates nn data centers, numbered from 1 to nn, spread across the world. They store client data. The company promises that clients can still reach their data when any one data center has an outage. This guarantee comes from two-way replication: every piece of data is stored as two identical copies in two different data centers.

The company has mm clients. For client ii, let ci,1c_{i,1} and ci,2c_{i,2} be the indices of the two different data centers that store that client's data.

Each data center installs a software update once a day. The day is exactly hh hours long, and each data center jj has a maintenance hour uju_j (0≤uj≤h−10 \leq u_j \leq h-1), during which it is unavailable. For every client, uci,1≠uci,2u_{c_{i,1}} \neq u_{c_{i,2}} must hold. Otherwise, both copies could be down at the same time and the client's data becomes inaccessible.

Timezone changes sometimes move a data center's maintenance time by one hour. To study this, the company runs an experiment. It picks a non-empty subset of data centers and moves each of their maintenance hours one hour later. If uj=h−1u_j = h-1, the new hour is 0. Otherwise it is uj+1u_j+1. The experiment must keep the guarantee intact: at every hour of the day, every client still has at least one reachable copy.

Changing a maintenance time is expensive, so find the smallest number of data centers that must be included in the experiment.

Input

The first line contains three integers nn, mm, and hh (2≤n≤100 0002 \leq n \leq 100\,000, 1≤m≤100 0001 \leq m \leq 100\,000, 2≤h≤100 0002 \leq h \leq 100\,000). The second line contains nn integers u1,u2,…,unu_1, u_2, \ldots, u_n (0≤uj<h0 \leq u_j < h). Each of the next mm lines contains two integers ci,1c_{i,1} and ci,2c_{i,2} (1≤ci,1,ci,2≤n1 \leq c_{i,1}, c_{i,2} \leq n, ci,1≠ci,2c_{i,1} \neq c_{i,2}). The input guarantees that the given schedule lets every client reach at least one copy at every moment of the day.

Output

On the first line, print the minimum number of data centers kk (1≤k≤n1 \leq k \leq n) that must be included in the experiment. On the second line, print kk distinct indices x1,x2,…,xkx_1, x_2, \ldots, x_k (1≤xi≤n1 \leq x_i \leq n) of the data centers whose maintenance hour moves one hour later. The order does not matter. If several answers exist, any of them is accepted. At least one valid choice is guaranteed to exist.

Hint

In the first sample, the printed answer is the only single data center that works. Data center 3 has maintenance at hour 0, and no two data centers that share a client have maintenance at the same hour. If you shift data center 1 instead, the data of clients 1 and 3 becomes unreachable at hour 0.

Examples2

  1. Example 1

    Input
    3 3 5
    4 4 0
    1 3
    3 2
    3 1
    
    Expected output
    1
    3
    
  2. Example 2

    Input
    4 5 4
    2 1 0 3
    4 3
    3 2
    1 2
    1 4
    1 3
    
    Expected output
    4
    1 2 3 4