zoukankan      html  css  js  c++  java
  • bzoj 1854: [Scoi2010]游戏

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #define M 2000008
     5 using namespace std;
     6 int pi[M],n,m,f[M],i,head[M],next[M],u[M],cnt,tim;
     7 bool xun(int a1)
     8 {
     9     for(int j=head[a1];j;j=next[j])
    10       if(f[u[j]]!=tim)
    11         {
    12             f[u[j]]=tim;
    13             if(!pi[u[j]]||xun(pi[u[j]]))
    14               {
    15                 pi[u[j]]=a1;
    16                 return 1;
    17               }
    18         }
    19     return 0;
    20 }
    21 void jia(int a1,int a2)
    22 {
    23     cnt++;
    24     next[cnt]=head[a1];
    25     head[a1]=cnt;
    26     u[cnt]=a2;
    27     return;
    28 }
    29 int main()
    30 {
    31     scanf("%d",&n);
    32     for( i=1;i<=n;i++)
    33       {
    34         int a1,a2;
    35         scanf("%d%d",&a1,&a2);
    36         jia(a1,i);
    37         jia(a2,i);
    38       }
    39     for( i=1;i<=10000;i++)
    40       {
    41         tim++;
    42         if(!xun(i))
    43           break;
    44       }
    45     printf("%d
    ",i-1);
    46 }

    属性与序号建边 跑二分图匹配。

  • 相关阅读:
    js的元素对象
    js实现在末尾添加节点
    js实现点击增加文本输入框
    js的DOM对象
    js其它
    js实现99乘法表
    js
    http的六种请求方法
    11.进制
    10.Debug
  • 原文地址:https://www.cnblogs.com/xydddd/p/5281986.html
Copyright © 2011-2022 走看看