zoukankan      html  css  js  c++  java
  • NC20566 游戏(二分图)

    感觉复杂度很有问题的

    但是这个算法比较好像,就是先连二分图,从最小权值一直做匹配

    数据可能并不是特别强,可能也是确实网络流的算法都是能跑较大数据

    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    typedef pair<int,int> pll;
    const int N=2e6+10;
    const int inf=0x3f3f3f3f;
    int match[N],st[N];
    int h[N],ne[N],e[N],idx;
    int now;
    void add(int a,int b){
        e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    }
    bool dfs(int u){
        int i;
        for(i=h[u];i!=-1;i=ne[i]){
            int j=e[i];
            if(st[j]==now)
                continue;
            st[j]=now;
            if(!match[j]||dfs(match[j])){
                match[j]=u;
                return true;
            }
        }
        return false;
    }
    int main(){
        ios::sync_with_stdio(false);
        int n;
        memset(h,-1,sizeof h);
        cin>>n;
        int i;
        for(i=1;i<=n;i++){
            int a,b;
            cin>>a>>b;
            add(a,i);
            add(b,i);
        }
        int ans=0;
        for(i=1;i<=10000;i++){
            now=i;
            if(dfs(i)){
                ans++;
            }
            else
                break;
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    bzoj1996
    bzoj2839
    bzoj1304
    bzoj1097
    bzoj4547
    bzoj3379
    bzoj3090
    树莓派/Debian 构建LAMP Web服务器并搭建WordPress博客(一)
    树莓派/Debian Apache2 配置自建 CA 实现 HTTPS(SSL) 服务
    树莓派/Debian Apache2 实现 HTTPS(SSL) 服务
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14514515.html
Copyright © 2011-2022 走看看