http://www.lydsy.com/JudgeOnline/problem.php?id=1854
武器和属性显然是两个集合相应的关系也很明显,剩下的就是傻逼的找增广路了。找不到直接退出。因为找不到肯定不连续么。
1 /**************************************************************
2 Problem: 1854
3 User: worfzyq
4 Language: C++
5 Result: Accepted
6 Time:3476 ms
7 Memory:14896 kb
8 ****************************************************************/
9
10 /*
11 by cao ni ma
12 hehe
13 */
14
15 #include <cstdio>
16 #include <cstring>
17 #include <algorithm>
18 #include <cmath>
19 #include <vector>
20 #include <list>
21 #include <queue>
22 #include <stack>
23 using namespace std;
24 typedef long long LL;
25
26 const int MAX = 100000+10;
27 const int inf = 0x3f3f3f3f;
28 vector <int> G[MAX];
29 int match[MAX],use[MAX];
30 int n,m;
31 int vis[MAX];
32 void add_edge(int from,int to) {
33 G[from].push_back(to);
34 }
35 void init() {
36
37 for(int i=0;i<MAX;i++) G[i].clear();
38 }
39 int dfs(int u) {
40 for(int i=0;i<G[u].size();i++) {
41 int v=G[u][i];
42 if(!use[v]) {
43 use[v]=1;
44 if(match[v]==-1||dfs(match[v])) {
45 match[v]=u;
46 return true;
47 }
48 }
49 }
50 return false;
51 }
52
53 int Full_match () {
54 memset(match,-1,sizeof(match));
55 int res=0;
56 for(int i=1;i<MAX;i++) {
57 memset(use,0,sizeof(use));
58 if(dfs(i)) res++;
59 else break;
60 }
61 return res;
62 }
63
64 int main()
65 {
66 //freopen("in","r",stdin);
67 //freopen("out","w",stdout);
68 int a,b;
69 while(scanf("%d",&n)==1) {
70 init();
71 for(int i=1;i<=n;i++) {
72 scanf("%d %d",&a,&b);
73 add_edge(a,i);
74 add_edge(b,i);
75 }
76 int ans=Full_match() ;
77 printf("%d ",ans);
78 }
79 return 0;
2 Problem: 1854
3 User: worfzyq
4 Language: C++
5 Result: Accepted
6 Time:3476 ms
7 Memory:14896 kb
8 ****************************************************************/
9
10 /*
11 by cao ni ma
12 hehe
13 */
14
15 #include <cstdio>
16 #include <cstring>
17 #include <algorithm>
18 #include <cmath>
19 #include <vector>
20 #include <list>
21 #include <queue>
22 #include <stack>
23 using namespace std;
24 typedef long long LL;
25
26 const int MAX = 100000+10;
27 const int inf = 0x3f3f3f3f;
28 vector <int> G[MAX];
29 int match[MAX],use[MAX];
30 int n,m;
31 int vis[MAX];
32 void add_edge(int from,int to) {
33 G[from].push_back(to);
34 }
35 void init() {
36
37 for(int i=0;i<MAX;i++) G[i].clear();
38 }
39 int dfs(int u) {
40 for(int i=0;i<G[u].size();i++) {
41 int v=G[u][i];
42 if(!use[v]) {
43 use[v]=1;
44 if(match[v]==-1||dfs(match[v])) {
45 match[v]=u;
46 return true;
47 }
48 }
49 }
50 return false;
51 }
52
53 int Full_match () {
54 memset(match,-1,sizeof(match));
55 int res=0;
56 for(int i=1;i<MAX;i++) {
57 memset(use,0,sizeof(use));
58 if(dfs(i)) res++;
59 else break;
60 }
61 return res;
62 }
63
64 int main()
65 {
66 //freopen("in","r",stdin);
67 //freopen("out","w",stdout);
68 int a,b;
69 while(scanf("%d",&n)==1) {
70 init();
71 for(int i=1;i<=n;i++) {
72 scanf("%d %d",&a,&b);
73 add_edge(a,i);
74 add_edge(b,i);
75 }
76 int ans=Full_match() ;
77 printf("%d ",ans);
78 }
79 return 0;
80 }