您的位置:首页 > 其它

[可图性判定 Havel-Hakimi定理 构造] Codeforces Gym 100269 NEERC 13 Northern K. Kids in a Friendly Class

2017-04-07 06:55 489 查看
黑点和白点的个数可以从小到大枚举

黑白点之间的连边是显然的

那么对于白点或黑点内部 我们就需要连边使得每个点度数相同

每次选两个剩余度最大的点相连是错误的

反例 6 2

那么应该怎么连 需要Havel-Hakimi定理

由非负数组成的非增序列s:d1,d2,⋯,dn(n≥2,d1≥1)是可图的,当仅当序列s1:d2−1,d3−1,⋅⋅⋅,dd1+1−1,dd1+2,⋯,dn

是可图的。

每次选一个剩余度最大的点,将其与其余度最大的若干个点连接使其度满足要求。

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef pair<int,int> abcd;

const int N=1000005;

int a,b,c,d;
int n,m;
priority_queue<abcd> Q;
abcd tmp
; int pnt;

int main(){
freopen("kids.in","r",stdin);
freopen("kids.out","w",stdout);
scanf("%d%d%d%d",&a,&b,&c,&d);
int t=__gcd(b,c),_x=b/t,_y=c/t;
int n,m;
for (m=b,n=c; m<=d || n<=a || (n&1)&&(a&1) || (m&1)&&(d&1);m+=_x,n+=_y);
printf("%d %d\n",n,m);
for (int i=1;i<=n;i++) Q.push(abcd(a,i));
while (!Q.empty()){
abcd t=Q.top(); Q.pop();
for (int i=1;i<=t.first;i++)
printf("%d %d\n",t.second,Q.top().second),tmp[i]=Q.top(),Q.pop();
for (int i=1;i<=t.first;i++)
if (--tmp[i].first)
Q.push(tmp[i]);
}
for (int i=1;i<=m;i++) Q.push(abcd(d,i));
while (!Q.empty()){
abcd t=Q.top(); Q.pop();
for (int i=1;i<=t.first;i++)
printf("%d %d\n",n+t.second,n+Q.top().second),tmp[i]=Q.top(),Q.pop();
for (int i=1;i<=t.first;i++)
if (--tmp[i].first)
Q.push(tmp[i]);
}
for (int i=1;i<=m;i++) Q.push(abcd(c,i));
for (int i=1;i<=n;i++){
for (int j=1;j<=b;j++){
abcd t=Q.top(); Q.pop();
printf("%d %d\n",i,t.second+n);
if (--t.first)
Q.push(t);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: