# 【BZOJ4025】二分图

Description

Input

Output

Sample Input

3 3 3

1 2 0 2

2 3 0 3

1 3 1 2
Sample Output

Yes

No

Yes
HINT

0时刻，出现两条边1-2和2-3。

1时刻。出现一条边1-3。

2时刻，1-2和1-3两条边消失。

n<=100000，m<=200000，T<=100000，1<=u,v<=n。0<=start<=end<=T。

Source

PoPoQQQ

P.S.颓了那么久最终開始干正事了..

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 100010
#define GET (ch>='0'&&ch<='9')
#define MAXINT 0x3f3f3f3f
using namespace std;
int n,m,T,Top,cnt;
int sta[MAXN<<1],top;
int In[MAXN<<1],on[MAXN<<1];
struct splay
{
int ch[2],fa,minn,st,sum,val;
bool rev;
}tree[MAXN<<2];
inline void in(int &x)
{
char ch=getchar();x=0;
while (!GET)    ch=getchar();
while (GET) x=x*10+ch-'0',ch=getchar();
}
struct edge
{
int u,v,w;
}e[MAXN<<1];
struct Edge
{
int to;
Edge *next;
}E[MAXN<<2],*prev1[MAXN],*prev2[MAXN];
inline void insert1(int u,int v)    {E[++Top].to=v;E[Top].next=prev1[u];prev1[u]=&E[Top];}
inline void insert2(int u,int v)    {E[++Top].to=v;E[Top].next=prev2[u];prev2[u]=&E[Top];}
inline bool is_root(int x)
{
return tree[tree[x].fa].ch[0]!=x&&tree[tree[x].fa].ch[1]!=x;
}
inline void push_down(int x)
{
if (tree[x].rev)
{
tree[tree[x].ch[0]].rev^=1,tree[tree[x].ch[1]].rev^=1;
swap(tree[x].ch[0],tree[x].ch[1]);
}
tree[x].rev=0;
}
inline void push_up(int x)
{
tree[x].minn=tree[x].val;tree[x].st=x;tree[x].sum=x>n;
if (tree[x].ch[0])
{
if (tree[tree[x].ch[0]].minn<tree[x].minn)  tree[x].minn=tree[tree[x].ch[0]].minn,tree[x].st=tree[tree[x].ch[0]].st;
tree[x].sum+=tree[tree[x].ch[0]].sum;
}
if (tree[x].ch[1])
{
if (tree[tree[x].ch[1]].minn<tree[x].minn)  tree[x].minn=tree[tree[x].ch[1]].minn,tree[x].st=tree[tree[x].ch[1]].st;
tree[x].sum+=tree[tree[x].ch[1]].sum;
}
}
inline void rot(int x)
{
int y=tree[x].fa,z=tree[y].fa,l,r;
l=(tree[y].ch[1]==x);r=l^1;
if (!is_root(y))    tree[z].ch[tree[z].ch[1]==y]=x;
tree[tree[x].ch[r]].fa=y;tree[y].fa=x;tree[x].fa=z;
tree[y].ch[l]=tree[x].ch[r];tree[x].ch[r]=y;
push_up(y);push_up(x);
}
inline void Splay(int x)
{
top=0;sta[++top]=x;
for (int i=x;!is_root(i);i=tree[i].fa)  sta[++top]=tree[i].fa;
while (top) push_down(sta[top--]);
while (!is_root(x))
{
int y=tree[x].fa,z=tree[y].fa;
if (!is_root(y))
{
if ((tree[y].ch[0]==x)^(tree[z].ch[0]==y))  rot(x);
else    rot(y);
}
rot(x);
}
}
inline void access(int x)
{
for (int i=0;x;i=x,x=tree[x].fa)    Splay(x),tree[x].ch[1]=i,push_up(x);
}
inline void make_root(int x)
{
access(x);Splay(x);tree[x].rev^=1;
}
{
make_root(x);tree[x].fa=y;
}
inline void cut(int x,int y)
{
make_root(x);access(y);Splay(y);tree[y].ch[0]=tree[x].fa=0;push_up(y);
}
inline void split(int x,int y)
{
make_root(x);access(y);Splay(y);
}
inline int find_root(int x)
{
/*access(x);Splay(x);
while (tree[x].ch[0])   x=tree[x].ch[0];*/
for (access(x),Splay(x);tree[x].ch[0];x=tree[x].ch[0]);
return x;
}
inline void ins(int x)
{
int u=e[x].u,v=e[x].v;
if (u==v)   {In[x]=1;cnt++;return;}
else
{
split(u,v);int y=tree[v].st-n;
if (e[y].w<e[x].w)
{
if (tree[v].sum&1^1)    In[y]=1,cnt++;
on[y]=0;on[x]=1;
}
else
if (tree[v].sum&1^1)    In[x]=1,cnt++;
}
}
inline void del(int x)
{
if (on[x])  cut(e[x].u,x+n),cut(e[x].v,x+n);
else    if (In[x])  cnt--;
}
int main()
{
in(n);in(m);in(T);int s,t;
for (int i=1;i<=n;i++)  tree[i].val=tree[i].minn=MAXINT,tree[i].st=i;
for (int i=1;i<=m;i++)
{
in(e[i].u);in(e[i].v);in(s);in(t);e[i].w=t;
insert1(s,i);insert2(t,i);
tree[i+n].val=tree[i+n].minn=t;tree[i+n].st=i+n;tree[i+n].sum=1;
}
for (int x=0;x<T;x++)
{
for (Edge *i=prev1[x];i;i=i->next)  ins(i->to);
for (Edge *i=prev2[x];i;i=i->next)  del(i->to);
puts(cnt?"No":"Yes");
}
}
posted @ 2017-08-21 09:29  wzzkaifa  阅读(458)  评论(0编辑  收藏  举报