|
| 1 | +# Vertex Cover Challenge |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +You are given an undirected graph G = (V, E) with |V| = N vertices and |E| = M edges. |
| 6 | +You must select a subset of vertices S ⊆ V to form a Vertex Cover. |
| 7 | + |
| 8 | +A subset S is a valid vertex cover if and only if: |
| 9 | + for every edge {u, v} ∈ E, at least one of its endpoints is in S. |
| 10 | + (i.e., u ∈ S or v ∈ S or both). |
| 11 | + |
| 12 | +This is a heuristic optimization problem. |
| 13 | +You are NOT required to find the theoretically optimal solution. |
| 14 | +Instead, you should try to minimize the size of the set S (denoted as |S|). |
| 15 | + |
| 16 | +Let: |
| 17 | + K* = the minimum vertex cover size (optimal solution). |
| 18 | + K = the size of the vertex cover found by your solution. |
| 19 | + |
| 20 | +The score is defined as: |
| 21 | + Score = K* / K * 100 |
| 22 | + |
| 23 | +Thus: |
| 24 | +- Score = 100.0 means you found an optimal vertex cover. |
| 25 | +- Larger K yields a smaller score. |
| 26 | +- Invalid solutions (where some edges are not covered) receive score = 0. |
| 27 | + |
| 28 | +The value K* is known to the judge but not to the contestant. |
| 29 | + |
| 30 | +## Input Format |
| 31 | + |
| 32 | +The first line contains two integers: |
| 33 | + N M |
| 34 | +where: |
| 35 | + 2 ≤ N ≤ 10,000 |
| 36 | + 1 ≤ M ≤ 500,000 |
| 37 | + |
| 38 | +The next M lines each contain two integers: |
| 39 | + u v |
| 40 | +representing an undirected edge {u, v}, |
| 41 | +with 1 ≤ u, v ≤ N and u ≠ v. |
| 42 | + |
| 43 | +Multiple edges between the same pair of vertices may appear but imply the same constraint. |
| 44 | + |
| 45 | +## Output Format |
| 46 | + |
| 47 | +Output exactly N lines. |
| 48 | + |
| 49 | +The i-th line must contain one integer x_i ∈ {0, 1}: |
| 50 | +- 1 indicates that vertex i is included in the vertex cover (i ∈ S). |
| 51 | +- 0 indicates that vertex i is excluded from the vertex cover (i ∉ S). |
| 52 | + |
| 53 | +Requirements: |
| 54 | +- For any edge {u, v} ∈ E, it must be true that x_u = 1 OR x_v = 1. |
| 55 | + |
| 56 | +## Scoring |
| 57 | + |
| 58 | +Let: |
| 59 | + K = Σ x_i (Total number of vertices selected, i.e., sum of 1s in output) |
| 60 | + K* = Optimal minimum vertex cover size (hidden) |
| 61 | + |
| 62 | +If the solution is invalid (i.e., there exists an edge {u, v} where x_u=0 and x_v=0): |
| 63 | + Score = 0 |
| 64 | + |
| 65 | +Otherwise: |
| 66 | + Score = K* / K * 100 |
| 67 | + |
| 68 | +Higher score is better. |
| 69 | + |
| 70 | +## Example |
| 71 | + |
| 72 | +Input: |
| 73 | +4 3 |
| 74 | +1 2 |
| 75 | +2 3 |
| 76 | +3 4 |
| 77 | + |
| 78 | +Output: |
| 79 | +0 |
| 80 | +1 |
| 81 | +1 |
| 82 | +0 |
| 83 | + |
| 84 | +Explanation: |
| 85 | +The edges are {1,2}, {2,3}, {3,4}. |
| 86 | +The output selects vertices 2 and 3 (S={2, 3}). |
| 87 | +- Edge {1,2} is covered by 2. |
| 88 | +- Edge {2,3} is covered by 2 (and 3). |
| 89 | +- Edge {3,4} is covered by 3. |
| 90 | +All edges are covered. |
| 91 | +Total size K = 2. |
| 92 | +Assuming the optimal K* = 2, the Score = 2 / 2 * 100 = 100.0. |
| 93 | + |
| 94 | +## Constraints |
| 95 | + |
| 96 | +- 2 ≤ N ≤ 10,000 |
| 97 | +- 1 ≤ M ≤ 500,000 |
| 98 | +- Time Limit: 2.0s |
| 99 | +- Memory Limit: 512MB |
0 commit comments