标签:转化 content 技术分享 ring 问题: alt via define desc
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define N 8007 5 using namespace std; 6 struct edge{ 7 int to,next; 8 }e[N]; 9 int n,m,tot,ls[N]; 10 int g[N],cnt,used[N]; 11 12 void add(int x,int y){ 13 e[++tot].to=y; 14 e[tot].next=ls[x]; 15 ls[x]=tot; 16 } 17 18 void Init(){ 19 scanf("%d%d",&n,&m); 20 for(int i=1;i<=m;i++){ 21 int x,y; 22 scanf("%d%d",&x,&y); 23 add(x,y+n); 24 add(y+n,x); 25 } 26 } 27 28 bool find(int x){ 29 for(int i=ls[x];i;i=e[i].next){ 30 int v=e[i].to; 31 if (used[v]) continue; 32 used[v]=1; 33 if (g[v]==0||find(g[v])){ 34 g[v]=x; 35 return 1; 36 } 37 } 38 return 0; 39 } 40 41 void Work(){ 42 for(int i=1;i<=n;i++){ 43 memset(used,0,sizeof(used)); 44 if (find(i)) cnt++; 45 } 46 } 47 48 int main(){ 49 freopen("phalanx.in","r",stdin); 50 freopen("phalanx.out","w",stdout); 51 Init(); 52 Work(); 53 printf("%d",cnt*n+(n-cnt)*2*n); 54 }
标签:转化 content 技术分享 ring 问题: alt via define desc
原文地址:https://www.cnblogs.com/traveller-ly/p/9892444.html