题面:
题意:
给定一张图,然后给定一些点的度数,问能不能通过删边来使得图中每个点的度数与给定的度数相等。
题解:
考虑一般图的最大匹配。
如果点 i 给定的度数是 di,那么我们把 i 拆分为di个点。
这样如果这di个点都在最大匹配当中,那么说明 i 点的度数符合要求。
如果原图中 i 与 j 有边相连,那么 di 个 i 点与 dj 个 j 点分别相连。
通过观察发现,如果di,dj不全大于等于2,那么这样连边是符合要求的。
假设 di = 1,dj = 2
那么 i – j,i – jj ,这样只能贡献一个匹配。
若di = 2,dj = 2
那么 i – j,i – jj,ii – j,ii – jj,这样就会出现一条边对于一个点贡献两个度的情况。
我们考虑把这条边拆开。
i – e,ii – e,j – ee,jj – ee,e – ee
然后再求一般图最大匹配。
若最终是 e 与 ee 匹配,那么说明我们不需要这条边,否则我们需要 e 与 i 的某个拆点匹配,ee 与 j 的某个拆点匹配,说明这条边需要。
那么最终,每个点都需要有与之匹配的点才可行。
假设拆点后的点的个数为cnt,那么我们求出的最大匹配ans*2==cnt才成立。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
//#define lc (cnt<<1)
//#define rc (cnt<<1|1)
#define len(x) (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=510;
const int maxm=100100;
const int up=1000;
int head[maxn],ver[maxn*maxn],nt[maxn*maxn],tot;
int ha[maxn],match[maxn],pre[maxn],f[maxn],id[maxn];
int n,m,idx,cnt,d[maxn],xx[maxn