#P6378. Key Vertices Selection in Partitioned Graph

    ID: 19594 Type: Default 1000ms 256MiB

Key Vertices Selection in Partitioned Graph

Key Vertices Selection in Partitioned Graph

Given an undirected graph with nn vertices and mm edges that is divided into kk parts, where each part contains some vertices, your task is to select exactly one vertex from each part (called a key vertex) such that every edge has at least one endpoint that is a key vertex. In other words, if the key vertex chosen in the part containing vertex uu is not uu and the key vertex chosen in the part containing vertex vv is not vv, then edge (u,v)(u,v) would not be covered. If a valid selection exists, output the key vertices for parts 11 through kk (in order) as space‐separated integers; otherwise, output -1.


Input Format:
The first line contains three integers nn, mm, and kk.
The second line contains nn integers, where the ii-th integer indicates the part number (from 1 to kk) to which vertex ii belongs.
Each of the next mm lines contains two integers uu and vv indicating an undirected edge between vertices uu and vv.
Output Format:
If a valid selection exists, output kk integers (the key vertices for parts 1 through kk, respectively) separated by single spaces; otherwise, output -1.

inputFormat

The first line contains three integers: n m k.

The second line contains n integers where the i-th integer (1-indexed) indicates the part number to which vertex i belongs (from 1 to k).

Then follow m lines, each containing two integers u and v (1-indexed) that denote an undirected edge between vertices u and v.

outputFormat

If there is a valid selection, output one line containing k space‐separated integers where the i-th integer is the key vertex chosen for part i. If no valid selection exists, output -1.

sample

4 3 2
1 1 2 2
1 3
2 4
3 4
2 3