BZOJ 3175 Tjoi2013 maximum matching of attack device bipartite graph

Source: Internet
Author: User

Given a grid map of n * n, some attack devices should be placed at 0. The attack scope of one of the attack devices is the surrounding eight "day" areas, it is required that no attack can be performed on each other, and the maximum number of attack devices can be placed

Each two vertex that can attack each other and can be placed connects a bidirectional edge, and then runs the maximum vertex independence set of the bipartite graph.

4 W points n ^ 2, isn't it because the data is too weak or the Hungarian algorithm is too strong?

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 210 using namespace std; struct abcd {int to, next ;} table [M * M <3]; int head [M * M], tot; int n, m, ans; int map [M] [M]; int state [M * M], result [M * M], T; const int dx [] = {1, 1, 2}; const int dy [] = {2, -2, 1,-1}; void Add (int x, int y) {table [++ tot]. to = y; table [tot]. next = head [x]; head [x] = tot;} bool Hungary (int x) {int I; for (I = head [x]; I; I = table [I]. next ) {If (state [table [I]. to] = T) continue; state [table [I]. to] = T; if (! Result [table [I]. to] | Hungary (result [table [I]. to]) {result [table [I]. to] = x; return true;} return false;} int main () {int I, j, k; cin> n; for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) {scanf ("% 1d ", & map [I] [j]); if (map [I] [j] = 1) map [I] [j] =-1; elsemap [I] [j] = ++ m;} for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) if (~ Map [I] [j]) for (k = 0; k <4; k ++) {int xx = I + dx [k]; int yy = j + dy [k]; if (xx <= 0 | yy <= 0 | xx> n | yy> n) continue; if (map [xx] [yy] =-1) continue; Add (map [I] [j], map [xx] [yy]); add (map [xx] [yy], map [I] [j]);} ans = m <1; for (I = 1; I <= m; I ++) {++ T; if (Hungary (I) -- ans;} cout <(ans> 1) <endl ;}


BZOJ 3175 Tjoi2013 maximum matching of attack device bipartite graph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.