HNU 13103 Easy Delete minimum vertex overwrite = maximum number of matches, hnu13103
Question link: Click the open link
Easy Delete |
Time Limit:1000 ms,Special Time Limit:2500 ms,Memory Limit:65536KB |
Total submit users:8,Accepted users:4 |
Problem 13103:No special judgement |
Problem description |
Huicpc0215 has downloaded a lots of files in his desktop. Since there are too program files in the desktop, he wants to delete some files in the desktop. But some files can't be deleted.
Each time he can choose one row or column to delete. but attention he can't choose one row or column that has a file which can't be deleted. given the position of all files, please get the minimum steps for huicpc0215 to delete all files that he wants to delete. |
Input |
There are multiple test cases. Each test case containing:
The first line contains one integer: N (1 <= N <= 1000), N lines follows. each line contains three integers: F (0 <= F <= 1), X (-1e9 <= V <= 1e9 ), Y (-1e9 <= V <= 1e9 ). F = 0 means this file can't be delete. F = 1 means this file must be deleted. and X and Y are the position of the file in the desktop. |
Output |
If huicpc0215 can achieve his goal, print minimum steps to achieve his goal, otherwise print "Sorry" in one line. |
Sample Input |
20 1 11 1 230 1 10 2 21 1 231 1 11 2 21 1 2 |
Sample Output |
1Sorry2 |
Question:
Point on n two-dimensional coordinates
N rows below:
Fi, xi, yi
If Fi = 0, this point cannot be deleted.
If Fi = 1, this point must be deleted.
You can select any row or column in each operation (Note that there cannot be any vertex in this row (column) to delete all the deletable vertices in this row.
Q: The minimum number of operations.
Ideas:
If all vertices must be deleted, the classic minimum vertices are overwritten.
In this question: there are three types of deletable points
1. There are points in the x y coordinate that cannot be deleted. At this time, the Sorry output
2. If x or y has a vertex that cannot be deleted, We forcibly select the row (or column) of the vertex and delete all vertices in the row.
3. After the above two operations, only x y does not exist and cannot be deleted. Such a vertex is the minimum vertex overwrite.
Minimum point coverage:
For a two-part graph, the graph has some edges.
To select the least vertex so that all edges are overwritten (when either of the edges is selected or both ends are selected at the same time, this edges are overwritten)
Yy certificate:
Minimum vertex overwrite = maximum number of matches
Those not selected points are collectively referred to as the largest group
So the largest group = X set points + Y set points-the minimum number of points covered
That is, the largest group = X set points + Y set points-the maximum number of matches
# Include <iostream> # include <stdio. h> # include <string. h> # include <set> # include <queue> # include <algorithm> # include <math. h> using namespace std; # define N 1005int lef [N], pn; // lef [v] indicates the current connection point of point v of the Y set, pn is the number of points in the x point set bool T [N]; // T [u] indicates whether the Y set u is connected to the X set vector <int> G [N]; // match edge G [X set]. push_back (Y set) Note that G initializes int sx [N], sy [N]; bool match (int x) {// returns whether point x matches successfully for (int I = 0; I <G [x]. size (); I ++) {int v = G [x] [I]; if (! T [v]) {T [v] = true; if (lef [v] =-1 | match (lef [v]) // match (lef [v]): Can the X-point lef [v] that originally connected to v be connected to others, if yes, the v point will be blank and x will be connected to {lef [v] = x; return true ;}}return false ;}int solve () {memset (lef, -1, sizeof (lef); int ans = 0; for (int I = 1; I <= pn; I ++) {memset (T, 0, sizeof T); if (match (I) {// printf ("OK: % d \ n", I); ans ++ ;}} return ans ;} vector <int> gx, gy; int f [N], x [N], y [N], a [N], B [N]; int n, papa; bool input (){ Gx. clear (); gy. clear (); for (int I = 1; I <= n; I ++) {scanf ("% d", & f [I], & x [I], & y [I]); gx. push_back (x [I]); gy. push_back (y [I]);} sort (gx. begin (), gx. end (); sort (gy. begin (), gy. end (); gx. erase (unique (gx. begin (), gx. end (), gx. end (); gy. erase (unique (gy. begin (), gy. end (), gy. end (); memset (sx, 0, sizeof sx); memset (sy, 0, sizeof sy); memset (a, 0, sizeof a); memset (B, 0, sizeof B); for (int I = 1; I <= n; I ++) {x [I] = lower_bound (gx. begin (), gx. end (), x [I])-gx. begin () + 1; y [I] = lower_bound (gy. begin (), gy. end (), y [I])-gy. begin () + 1; if (f [I] = 0) {sx [x [I] = sy [y [I] = 1 ;}} for (int I = 1; I <= (int) gx. size (); I ++) G [I]. clear (); papa = 0; for (int I = 1; I <= n; I ++) {if (f [I] = 0) continue; if (sx [x [I] & sy [y [I]) return false; if (sx [x [I]) {if (B [y [I]) continue; B [y [I] = 1; papa ++;} else if (sy [y [I]) {if (a [x [I]) Continue; a [x [I] = 1; papa ++ ;}}for (int I = 1; I <= n; I ++) {if (f [I] = 0) continue; if (a [x [I] | B [y [I]) continue; G [x [I]. push_back (y [I]);} return true;} int main () {while (~ Scanf ("% d", & n) {if (false = input () {puts ("Sorry"); continue;} pn = (int) gx. size (); int ans = solve (); // printf ("(number of matching edges % d) \ n", ans); ans = papa + ans; // printf ("pn: % d \ nGX:", pn); for (int I = 0; I <gx. size (); I ++) printf ("% d", gx [I]); cout <"\ n" <"GY :"; for (int I = 0; I <gy. size (); I ++) printf ("% d", gy [I]); puts (""); printf ("% d \ n", ans );} return 0 ;} /* 41 1 11 2 21 1 20 2 161 1 11 2 21 1 20 2 10 2 30 1 031 1 21 1 31 1 451 0 01 1 00 2 01 1 10 2 1250 1 10 1 20 1 30 2 10 2 20 2 30 3 10 3 20 3 31 0 01 1 01 2 01 3 01 4 01 0 21 4 21 0 11 4 11 0 31 4 31 0 0 41 4 41 1 41 2 41 3 4251 1 11 1 21 1 31 2 10 2 21 2 31 3 11 3 31 31 0 01 1 01 2 01 3 01 4 01 0 21 4 21 0 11 4 11 0 31 4 31 0 41 4 41 1 41 2 41 3 431 1 11 1 1 2 */