您当前的位置: 首页 > 

钟钟终

暂无认证

  • 4浏览

    0关注

    232博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

二分图的时间戳优化+并查集变型

钟钟终 发布时间:2022-03-18 00:01:42 ,浏览量:4

P1640 [SCOI2010]连续攻击游戏

用used数组记录now(now++),不需要每一轮都是用memset判别。

#include 

using namespace std;
const int maxn=4e6+5;
int n,link[maxn],ans,cnt,now,head[maxn];
int used[maxn];
struct node
{
    int to,nxt;
}e[maxn];
void add(int u,int v)
{
    e[++cnt].to=v;
    e[cnt].nxt=head[u];
    head[u]=cnt;
}
int dfs(int u)
{
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;
        if(used[v]!=now)
        {
            used[v]=now;
            if(link[v]==-1||dfs(link[v]))
            {
                link[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
void hungary()
{
    memset(link,-1,sizeof(link));
    for(int i=1;i>n;
    for(int i=1;i>u>>v;
        add(u,i);add(v,i);
    }
    hungary();
    cout            
关注
打赏
1664378814
查看更多评论
0.0541s