社区讨论
刘汝佳坑害小萌新!!!
P1330封锁阳光大学参与者 9已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 11 条
- 当前快照
- 1 份
- 快照标识符
- @mi7x7ur3
- 此快照首次捕获于
- 2025/11/21 05:05 4 个月前
- 此快照最后确认于
- 2025/11/21 06:37 4 个月前
先是用二染色
#成功
然后改成了版,本机仍跑不过# 求助
CPP#成功
然后改成了版,本机仍跑不过# 求助
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=10000 + 10;
const int maxm=100000 + 10;
int head[maxn],color[maxn];
int en=0,n,m;
queue<int>q;
struct edge
{
int v,next;
}e[maxm];
inline void add(int u,int v) {
e[en].next=head[u];
e[en].v=v;
head[u]=en++;
}
inline void read(int &a) {
int c; a=0;
while((c=getchar())) if(c>='0'&&c<='9') break;
do {
a=a*10+c-'0';
c=getchar();
}while(c>='0'&&c<='9');
}
int main() {
//freopen("in.in","r",stdin);
int u,v,S,black,ans=0;
memset(head,-1,sizeof(head));
read(n); read(m);
for(int i=0;i<m;i++) {
read(u); read(v);
add(u,v); add(v,u);
}
for(int s=1;s<=n;s++) if(!color[s]) {
S=black=1; color[s]=1; q.push(s);
while(!q.empty()) {
int u=q.front(); q.pop();
for(int i=head[u];i!=-1;i=e[i].next) {
int v=e[i].v;
if(color[u]==color[v]) return 0&printf("Impossible\n");
if(!color[v]) {
color[v]=3-color[u];
q.push(v);
if(color[v]&1) black++;
S++;
}
}
}
int x=min(S-black,black);
ans+=x;
}
printf("%d\n",ans);
return 0;
}
回复
共 11 条回复,欢迎继续交流。
正在加载回复...