Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // First one as a matrix. Geeks for geeks
- int bpGraph[104][104], seen[104];
- int matchR[104];
- int n;
- pii stu[104], tut[104];
- bool bpm(int u){
- for (int v = 0; v < n; v++){
- if (bpGraph[u][v] && !seen[v]){
- seen[v] = true;
- if (matchR[v] < 0 || bpm(matchR[v])){
- matchR[v] = u;
- return true;
- }
- }
- }
- return false;
- }
- int maxBPM(){
- memset(matchR, -1, sizeof(matchR));
- int result = 0;
- for (int u = 0; u < n; u++){
- memset(seen, 0, sizeof(seen));
- if (bpm(u))
- result++;
- }
- return result;
- }
- void geni(int m){
- memset(bpGraph, 0, sizeof bpGraph);
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- int a = abs(stu[i].fi - tut[j].fi) + abs(stu[i].se - tut[j].se);
- if(a<=m) bpGraph[i][j] = 1;
- }
- }
- }
- // Second one for graph
- bool seen[1004];
- int matchR[1004];
- int n, m;
- vector <int> bpGraph[1004];
- bool bpm(int u){
- for (auto v: bpGraph[u]){
- if (!seen[v]){
- seen[v] = true;
- if (matchR[v] == -1 || bpm(matchR[v])){
- matchR[v] = u;
- matchR[u] = v;
- return true;
- }
- }
- }
- return false;
- }
- int maxBPM(){
- memset(matchR, -1, sizeof(matchR));
- int result = 0;
- for (int u = 1; u <= n; u++){
- memset(seen, false, sizeof(seen));
- if (~matchR[u] || !bpm(u))
- result++;
- }
- return result;
- }
- void geni(){
- si(n); si(m);
- for(int i=1;i<=n;i++) bpGraph[i].clear();
- for(int i=0;i<m;i++){
- int a, b;
- si(a); si(b);
- bpGraph[a].pb(b);
- bpGraph[b].pb(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement