码迷,mamicode.com
首页 > 其他好文 > 详细

二分图匹配模板题

时间:2018-10-07 22:04:38      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:main   mail   ++   span   ret   map   str   mes   opened   

2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest 

技术分享图片
 1 /*************************************************************************
 2     > File Name: a.cpp
 3     > Author: QWX
 4     > Mail: 
 5     > Created Time: Fri 05 Oct 2018 06:37:54 AM PDT
 6  ************************************************************************/
 7 
 8 
 9 //{{{ #include
10 #include<iostream>
11 #include<cstdio>
12 #include<algorithm>
13 #include<vector>
14 #include<cmath>
15 #include<queue>
16 #include<map>
17 #include<set>
18 #include<string>
19 #include<cstring>
20 #include<complex>
21 #include<bits/stdc++.h>
22 #define mp make_pair
23 #define pb push_back
24 #define first fi
25 #define second se
26 #define pw(x) (1ll << (x))
27 #define sz(x) ((int)(x).size())
28 #define all(x) (x).begin(),(x).end()
29 #define rep(i,l,r) for(int i=(l);i<(r);i++)
30 #define per(i,r,l) for(int i=(r);i>=(l);i--)
31 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
32 #define eps 1e-9
33 #define pii pair<int,int>
34 #define vi vector<int> 
35 #define PIE acos(-1)
36 #define cl(a,b) memset(a,b,sizeof(a))
37 #define fastio ios::sync_with_stdio(false);cin.tie(0);
38 #define lson l , mid , ls
39 #define rson mid + 1 , r , rs
40 #define ls (rt<<1)
41 #define rs (ls|1)
42 #define INF 0x3f3f3f3f
43 #define LINF 0x3f3f3f3f3f3f3f3f
44 #define ll long long
45 #define ull unsigned long long
46 #define dd(x) cout << #x << " = " << (x) << "," 
47 #define de(x) cout << #x << " = " << (x) << "\n" 
48 #define endl "\n"
49 using namespace std;
50 //}}}
51 int n,a,b;
52 const int N=507;
53 vi g[N],v0,v1;
54 
55 namespace maxmatch
56 {
57     int link[N],vis[N];
58     bool dfs(int c){
59         for(auto t:g[c]){
60             if(vis[t])continue;vis[t]=1;
61             if(link[t]==-1||dfs(link[t]))return link[t]=c,1;
62         }
63         return 0;
64     }
65     int solve(int n,int m){
66         cl(link,-1);
67         int ret=0;
68         rep(i,0,n){
69             cl(vis,0);
70             ret+=dfs(i);
71         }
72         return ret;
73     }
74 }
75 
76 int main()
77 {
78     cin>>a>>b>>n;
79     int s0=0,s1=0;
80     rep(i,0,n){
81         int t,op;
82         cin>>t>>op;
83         if(op==0)s0++,v0.pb(t);
84         else if(op==1)s1++,v1.pb(t);
85     }
86     rep(i,0,sz(v0))rep(j,0,sz(v1)){
87         if(v1[j]-v0[i]>=a||(v1[j]-v0[i]<=b&&v1[j]-v0[i]>=0))
88             g[i].pb(j);
89     }
90     int ans=maxmatch::solve(s0,s1);
91 //    de(ans); 
92     if(s0==s1&&ans==s0){
93         puts("No reason");
94         rep(i,0,sz(v0))cout<<v0[maxmatch::link[i]]<<" "<<v1[i]<<endl;
95     }else puts("Liar");
96     return 0;
97 }
View Code

 

二分图匹配模板题

标签:main   mail   ++   span   ret   map   str   mes   opened   

原文地址:https://www.cnblogs.com/klaycf/p/9751641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!