T1 ,图的连通性
题意:给一个图,支持删除操作,询问任意时刻两个点的连通性
观察到只有删除操作,那么可以考虑倒着处理
先把所有将来会删除的边删掉,然后从最后一组询问倒着处理
并查集维护连通性
这里的强制在线是骗人的
在任意时刻图中剩下的边数都是可以离线处理出来的
一个小trick
重边,删除的时候只删除一条
用set 或者map判断当前该边的数量 {cnt,disable}
当cnt==disable时,两点不连通
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>
#include<cctype>
#include<algorithm>
#ifdef WIN32
#define AUTO "%I64d"
#else
#define AUTO "%lld"
#endif
using namespace std;
#define smax(x,tmp) x=max((x),(tmp))
#define smin(x,tmp) x=min((x),(tmp))
#define maxx(x1,x2,x3) max(max(x1,x2),x3)
#define minn(x1,x2,x3) min(min(x1,x2),x3)
const int INF=0x3f3f3f3f;
const int maxn = 100005;
const int maxm = 150005;
const int maxq = 100005;
inline void read(int &x)
{
x = 0;
int flag = 1;
char ch = getchar();
while(ch<'0' || ch>'9')
{
ch=getchar();
if(ch == '-') flag = -1;
}
while(ch>='0' && ch<='9')
{
x*=10; x+=ch-'0';
ch = getchar();
}
x *= flag;
}
struct Road
{
int x,y;
int cnt,disable;
bool operator < (const Road t) const
{
if(x ^ t.x) return x < t.x;
else return y < t.y;
}
}road[maxm];
set <Road> st;
set <Road> ::iterator it;
struct Query
{
int x,y;
int id;
int ans;
}que[maxq];
int n,m,q;
int maxedge;
void init()
{
maxedge=0;
read(n); read(m); read(q);
for(int i=1;i<=m;i++)
{
int x,y;
read(x); read(y);
if(x>y) swap(x,y);
it = st.find((Road){x,y,0,0});
if(it!=st.end())
{
Road tmp = (*it);
st.erase(it);
tmp.cnt++;
st.insert(tmp);
}
else st.insert((Road){x,y,