分析:贪心地删边后检查每个点的度即可,这也是正确的做法?
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4+5;
struct Edge{
int u,v,next;
}edges[MAXN<<2];
int head[MAXN],tot;
int deg[MAXN];
void init()
{
memset(head,-1,sizeof(head));
tot =0 ;
memset(deg,0,sizeof(deg));
}
void AddEdge(int u,int v)
{
edges[tot] = (Edge){u,v,head[u]};
head[u] = tot++;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int cas = 1;
int N,M,K,u,v;
while(scanf("%d %d %d",&N,&M,&K)==3){
init();
memset(deg,0,sizeof(deg));
int L,R; scanf("%d %d",&L, &R);
for(int i=1;i<=K;++i){
scanf("%d %d",&u,&v);
v+=N;
AddEdge(u,v);
deg[u]++; deg[v]++;
}
for(int e=0;e<tot;++e){
u = edges[e].u, v =edges[e].v;
if(deg[u]>R || deg[v]>R){
deg[u]--;
deg[v]--;
}
}
bool flag = true;
for(int i=1;i<=N+M;++i){
if(deg[i]<L || deg[i]>R){
flag = false;
break;
}
}
printf("Case %d: ",cas++);
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}
原文地址:https://www.cnblogs.com/xiuwenli/p/9610142.html
时间: 2024-10-28 11:35:24