Revmatching
2015 TCO 1A · 2015-04-08 · by subscriber
Problem Statement
You have a weighted bipartite graph.
Each partition contains n vertices numbered 0 through n-1.
You are given the weights of all edges encoded into a
A perfect matching is a permutation p of 0 through n-1 such that for each i there is an edge (of any positive weight) between vertex i in the first partition and vertex p[i] in the second partition.
Your goal is to have a graph that does not contain any perfect matching. You are allowed to delete edges from your current graph. You do not care about the number of edges you delete, only about their weights. More precisely, you want to reach your goal by deleting a subset of edges with the smallest possible total weight. Compute and return the total weight of deleted edges in an optimal solution.
Constraints
- A will contain exactly n elements.
- Each element in A will be n characters long.
- n will be between 1 and 20, inclusive.
- Each character in A will be between '0' and '9', inclusive.
{"1"}
Returns: 1
There is a single edge. You have to delete it.
{"0"}
Returns: 0
There are no edges and therefore there is no perfect matching.
{"44","44"}
Returns: 8
{"861","870","245"}
Returns: 6
{"01000","30200","11102","10001","11001"}
Returns: 0
Submissions are judged against all 76 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Revmatching with a public method int smallest(vector<string> A) · 76 test cases · 2 s / 256 MB per case