Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1191
Today casually in Bzoj to find a problem to do, the first read on the discovery is a Hungarian algorithm naked, originally thought can once, the result WA has not less than five times, deeply ashamed, I changed the method, did not use adjacent linked list, instead of the adjacency matrix, the results suddenly went through, which let me very much is a crazy, I haven't figured out what's wrong with my adjacency list right now.
This question is purely naked, without a trace of the difficulty of the mind, but I have a small deal with a place, this place processing or not processing will not affect the final answer, that is, I put the Jin sac label 0~n-1 all plus 1 into the 1~n (PS: Obsessive-compulsive disorder, does not affect the answer)
First of all, look at my adjacency list method, I did not find out where the mistake, kneel beg you to help me find fault!!!
Orz Orz Orz Orz Orz
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7#include <queue>8 #defineMAXN 10059 using namespacestd;Ten One structedge{ A intu,v,nxt; -}e[maxn<<2]; - the intVIS[MAXN],ATT[MAXN],HEAD[MAXN]; - intN,m,ans; - - intpos=1; + voidAdde (intUintv) - { +e[pos].u=u; Ae[pos].v=v; ate[pos].nxt=Head[u]; -head[u]=pos++; - } - - BOOLCanintx) - { in for(intI=head[x];i;i=e[i].nxt) - { to intv=e[i].v; + if(vis[v]==0) - { thevis[v]=1; * if(Can (Att[v]) | |!Att[v]) $ {Panax Notoginsengatt[v]=x; - return 1; the } + } A } the return 0; + } - $ intMain () $ { -Memset (ATT,0,sizeof(ATT)); -Memset (Head,0,sizeof(head)); thescanf"%d%d",&n,&m); - for(intI=1; i<=m;i++)Wuyi { the intb; -scanf"%d%d",&a,&b); Wua++;b++; - if(a!=b) About { $ Adde (i,a); - Adde (i,b); -}ElseAdde (i,a); - } A for(intI=1; i<=m;i++) + { thememset (Vis,0,sizeof(Vis)); - if(Can (i)) ans++; $ Else Break; the } thecout<<ans; the}
View Code
PS: This is a non-AC code ↑
Then I changed the adjacency matrix, this code is one time past, but let me suddenly confused (the list which is wrong???? )
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7#include <queue>8 #defineMAXN 10059 using namespacestd;Ten One A intMAP[MAXN][MAXN]; - intVIS[MAXN],ATT[MAXN]; - intN,m,ans; the - BOOLCanintx) - { - for(intI=1; i<=n;i++) + { - if(map[x][i]==1&&vis[i]==0) + { Avis[i]=1; at if(!att[i]| |can (Att[i])) - { -att[i]=x; - return 1; - } - } in - } to return 0; + } - the intMain () * { $Memset (ATT,0,sizeof(ATT));Panax Notoginsengscanf"%d%d",&n,&m); - for(intI=1; i<=m;i++) the { + intb; Ascanf"%d%d",&a,&b); themap[i][a+1]=1; map[i][b+1]=1; + } - for(intI=1; i<=m;i++) $ { $memset (Vis,0,sizeof(Vis)); - if(Can (i)) ans++; - Else Break; the } -cout<<ans;Wuyi}
View Code
PS: List of problems also hope you guys find the problem and point out Orz
[bzoj1191] superhero hero< binary map matching * Hungarian algorithm >