Bzoj 1854: [Scoi2010] Game (binary graph Max match)

Source: Internet
Author: User

Hungarian algorithm: From the 1~10000 in turn to find the augmented road, can not find the stop, output answer.  

----------------------------------------------------------------------------

#include <bits/stdc++.h>using namespace std;const int MAXL = 10009, MAXR = 1000009;struct Edge {int to;edge* Next;} E[MAXR << 1], *pt = E, *head[maxl];inline void Addedge (int u, int v) {pt->to = v; pt->next = head[u];Head[u] = pt++;}int MATCH[MAXR], vis[maxr], N, C;bool Dfs (int x) {For (edge* e = head[x]; e; e = e->next) if (vis[e->to]! = C) {vis[e->to] = C;if (!~match[e->to] | | DFS (MATCH[E->TO)) {match[e->to] = x;return true;}}return false;}int main () {memset (Match,-1, sizeof match);memset (Vis,-1, sizeof vis);scanf ("%d", &n);for (int i = 0; i < N; i++) {int A, b; scanf ("%d%d", &a, &b); a--; b-- ;Addedge (A, I); Addedge (b, i);}int ans = 0;For (C = 0; C < 10000; C + +) {if (Dfs (C)) ans++;else break;}printf ("%d\n", ans);return 0;}

----------------------------------------------------------------------------

1854: [Scoi2010] Game time limit: 5 Sec Memory Limit: 162 MB
Submit: 3022 Solved: 1100
[Submit] [Status] [Discuss] DESCRIPTIONLXHGWW has recently been fascinated by a game in which he has a lot of equipment, each with 2 attributes, the values of which are expressed in numbers between [1,10000]. When he uses some kind of equipment, he can only use one of the properties of the equipment. And each device can be used at most once. At the end of the game, LXHGWW encountered the ultimate boss, the ultimate boss is very strange, attack his equipment used by the attribute value must start from 1 continuous incremental attack, in order to damage the boss. In other words, at first, LXHGWW can only use a device with a property value of 1 to attack the boss, and then only use a device with a property value of 2 to attack the boss, and then only use a property value of 3 of the equipment attack boss ... And so on Now LXHGWW want to know how many times he can attack bosses in succession? The first line of input inputs is an integer n, which means that LXHGWW has n equipment next n lines, is a description of the n equipment, 2 numbers per line, representing the 2 attribute values of the equipment of the first I output a row, including 1 numbers, indicating the maximum number of consecutive attacks Lxhgww. Sample Input3
1 2
3 2
4 5
Sample Output2
HINT

"Data Range"
For 30% of data, ensure n < =1000
For 100% of data, ensure n < =1000000

Source

Day1

Bzoj 1854: [Scoi2010] Game (binary graph Max match)

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.