4025: 二分图

考虑二分图的判定就是看图内是否有奇环...

因为存在一条公共边的两个偶环还是会构成一个偶环,

那么用lct维护以时间为权值的最大生成树,这样可以保证如果有奇环,一定是和树上的边构成的...

然后注意一下细节就好了...

(↑这傻逼调了一天)

c++代码如下:

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x ; i <= y ;++ i)
#define repd(i,x,y) for(register int i = x ; i >= y ;-- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
    x = 0;char c;int sign = 1;
    do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
    do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
    x *= sign;
}
 
const int N = 1e6 + 500,M = 1e6 + 500,P = 2e6+50;
struct Str { int u,v,t,id; bool op; }edge[M];
struct Data{ int u,v; } a[M];
int n,m,t,cnt;
 
const bool cmp(Str a,Str b) { return (a.t < b.t) || (a.t==b.t&&a.op < b.op); }
 
struct Link_Cut_Tree
{
    int ch[P][2],f[P],val[P],rev[P],sum[P],t[P],id[P],num;
    bool flag[P],_is[P];
     
    #define lc ch[x][0]
    #define rc ch[x][1]
     
    inline void pre() { memset(t,0x3f,sizeof t);rep(i,1,n+m) id[i] = i; }
     
    inline bool isroot(int x) { return !(ch[f[x]][0] == x || ch[f[x]][1] == x); }
     
    inline bool get(int x) { return ch[f[x]][1] == x; }
     
    inline void update(int x)
    {
        sum[x] = sum[lc] + sum[rc] + val[x];
        id[x] = x;
        if(t[id[lc]] < t[id[x]]) id[x] = id[lc];
        if(t[id[rc]] < t[id[x]]) id[x] = id[rc];
    }
     
    inline void rotate(int x)
    {
        int fa = f[x],t = get(x);
        f[x] = f[fa];
        if(!isroot(fa)) ch[f[x]][get(fa)] = x;      
        ch[fa][t] = ch[x][t^1];
        if(ch[fa][t]) f[ch[fa][t]] = fa;
        ch[x][t^1] = fa; f[fa] = x;
        update(fa); update(x);
    }
     
    void put_down(int x)
    {
        if(!isroot(x)) put_down(f[x]);
        if(rev[x])
        {
            rev[lc] ^= 1;rev[rc] ^= 1;
            swap(lc,rc); 
            rev[x] ^= 1;
        } 
    }
     
    inline void splay(int x)
    {
        put_down(x);
        while(!isroot(x))
        {
            if(!isroot(f[x])) rotate(get(x) == get(f[x]) ? f[x] : x);
            rotate(x);
        }
    }
     
    inline void access(int x)
    {
        int t = 0;
        while(x)
        {
            splay(x);
            ch[x][1] = t;
            update(x);
            t = x;
            x = f[x];
        }
    }
     
    inline void mkroot(int x) { access(x); splay(x); rev[x] ^= 1; }
     
    inline void cut(int x,int y)
    {
        mkroot(x);
        access(y);
        splay(y);
        f[x] = 0;
        ch[y][0] = 0;
        update(y);
    }
     
    inline int find_root(int x)
    {
        access(x); splay(x);
        while(lc) x = lc;
        return x;
    }
     
    inline void Link(int x,int y) { mkroot(x);f[x] = y; }
     
    inline void modify(int i)
    {
        int x = edge[i].u,y = edge[i].v;
         
        if(edge[i].op == 1)
        {
            if(flag[edge[i].id]) num--;
            if(_is[edge[i].id])
            {
                cut(x,edge[i].id+n);
                cut(y,edge[i].id+n);
            }
        }
        else
        {
            if(x == y)
            {
                flag[edge[i].id] = 1;
                ++num;
                return;
            }
            if(find_root(x) != find_root(y))
            {
            	_is[edge[i].id] = 1;
                Link(x,edge[i].id + n);Link(y,edge[i].id + n);
                return;
            }
             
            mkroot(x);access(y); splay(y);
            
             
            if(t[id[y]] > t[edge[i].id + n])
            {
				if(!(sum[y] & 1)) flag[edge[i].id] = 1,++num;
				return;
			} 
             
            if(!(sum[y] & 1)) flag[id[y]-n] = 1,++num;
            int p = id[y];
            _is[edge[i].id] = 1;_is[p - n] = 0;
            cut(a[p - n].u,p); cut(a[p - n].v,p);
            Link(x,edge[i].id + n),Link(y,edge[i].id + n);
        } 
    }
     
}lct;
 
int main()
{
	freopen("1.in","r",stdin);
	freopen("my.out","w",stdout);
    read(n);read(m); read(t);
    lct.pre();
    rep(i,1,m)
    {
    	int u,v,s,t;
        read(u); read(v); read(s); read(t);
        if(s == t) continue;
        a[i].u = u; a[i].v = v; 
        edge[++cnt].u = u;edge[cnt].v = v;
        edge[cnt].t = s;edge[cnt].id = i;edge[cnt].op = 0;
        edge[++cnt].u = u;edge[cnt].v = v;
        edge[cnt].t = t;edge[cnt].id = i;edge[cnt].op = 1;
        lct.t[i + n] = t;lct.val[i + n] = 1;
    }
     
    sort(edge + 1 ,edge + 1 + cnt ,cmp);
     
    int now = 1;
    rep(i,1,t)
    {
        while(edge[now].t < i && now <= cnt)
        {
            lct.modify(now);
            now++;
        }
        puts(lct.num ? "No" : "Yes");
    }
     
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值