Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions algorithmic/problems/182/checker.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "testlib.h"
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
// 初始化 testlib
registerTestlibCmd(argc, argv);

// 1. 读取输入数据 (Input)
int N = inf.readInt();
int M = inf.readInt();

// 存储边列表,用于验证覆盖
vector<pair<int, int>> edges;
edges.reserve(M);
for (int i = 0; i < M; i++) {
int u = inf.readInt();
int v = inf.readInt();
edges.push_back({u, v});
}

// 2. 读取标准答案 (Answer)
// 修改处:ans 文件中只包含一个整数 K* (最优/参考解的大小)
int K_optimal = ans.readInt();

// 3. 读取选手输出 (Output) 并统计 K
vector<int> user_sol(N + 1); // 1-based indexing
int K_user = 0;

for (int i = 1; i <= N; i++) {
// 读取 0 或 1
int val = ouf.readInt(0, 1, format("x_%d", i));
user_sol[i] = val;
if (val == 1) {
K_user++;
}
}

// 4. 验证选手的解是否有效 (Validity Check)
for (int i = 0; i < M; i++) {
int u = edges[i].first;
int v = edges[i].second;

// 如果一条边的两个端点都没被选中
if (user_sol[u] == 0 && user_sol[v] == 0) {
quitf(_wa, "Edge %d-%d is not covered (vertices %d and %d are both 0).", u, v, u, v);
}
}

// 5. 计算得分 (Scoring)
if (K_user == 0) {
if (M == 0) {
quitf(_ok, "Ratio: 1");
} else {
quitf(_wa, "Logic error: Valid solution found with size 0 for non-empty graph.");
}
}

double score = (double)K_optimal / K_user * 100.0;
double Ratio = (double)K_optimal / K_user;

// 6. 输出结果
quitf(_ok, "Valid Vertex Cover. K_user=%d, K_jury=%d, Ratio: %.4f", K_user, K_optimal, Ratio);

return 0;
}
8 changes: 8 additions & 0 deletions algorithmic/problems/182/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: default
time: 2s
memory: 512m
subtasks:
- score: 100
n_cases: 3
checker: checker.cc
checker_type: testlib
99 changes: 99 additions & 0 deletions algorithmic/problems/182/statement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Vertex Cover Challenge

## Context

You are given an undirected graph G = (V, E) with |V| = N vertices and |E| = M edges.
You must select a subset of vertices S ⊆ V to form a Vertex Cover.

A subset S is a valid vertex cover if and only if:
for every edge {u, v} ∈ E, at least one of its endpoints is in S.
(i.e., u ∈ S or v ∈ S or both).

This is a heuristic optimization problem.
You are NOT required to find the theoretically optimal solution.
Instead, you should try to minimize the size of the set S (denoted as |S|).

Let:
K* = the minimum vertex cover size (optimal solution).
K = the size of the vertex cover found by your solution.

The score is defined as:
Score = K* / K * 100

Thus:
- Score = 100.0 means you found an optimal vertex cover.
- Larger K yields a smaller score.
- Invalid solutions (where some edges are not covered) receive score = 0.

The value K* is known to the judge but not to the contestant.

## Input Format

The first line contains two integers:
N M
where:
2 ≤ N ≤ 10,000
1 ≤ M ≤ 500,000

The next M lines each contain two integers:
u v
representing an undirected edge {u, v},
with 1 ≤ u, v ≤ N and u ≠ v.

Multiple edges between the same pair of vertices may appear but imply the same constraint.

## Output Format

Output exactly N lines.

The i-th line must contain one integer x_i ∈ {0, 1}:
- 1 indicates that vertex i is included in the vertex cover (i ∈ S).
- 0 indicates that vertex i is excluded from the vertex cover (i ∉ S).

Requirements:
- For any edge {u, v} ∈ E, it must be true that x_u = 1 OR x_v = 1.

## Scoring

Let:
K = Σ x_i (Total number of vertices selected, i.e., sum of 1s in output)
K* = Optimal minimum vertex cover size (hidden)

If the solution is invalid (i.e., there exists an edge {u, v} where x_u=0 and x_v=0):
Score = 0

Otherwise:
Score = K* / K * 100

Higher score is better.

## Example

Input:
4 3
1 2
2 3
3 4

Output:
0
1
1
0

Explanation:
The edges are {1,2}, {2,3}, {3,4}.
The output selects vertices 2 and 3 (S={2, 3}).
- Edge {1,2} is covered by 2.
- Edge {2,3} is covered by 2 (and 3).
- Edge {3,4} is covered by 3.
All edges are covered.
Total size K = 2.
Assuming the optimal K* = 2, the Score = 2 / 2 * 100 = 100.0.

## Constraints

- 2 ≤ N ≤ 10,000
- 1 ≤ M ≤ 500,000
- Time Limit: 2.0s
- Memory Limit: 512MB
1 change: 1 addition & 0 deletions algorithmic/problems/182/testdata/1.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5800
Loading