封锁阳光大学

思路:

  bfs染色;

  如果当前点能通往已染色的点则不能完成;

  图不一定联通;

来,上代码:

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 10005
#define maxm 200005 struct EdgeType {
int v,e;
};
struct EdgeType edge[maxm]; int n,m,cnt,head[maxn],dis[maxn],ans; bool if_[maxn],ifo; inline void in(int &now)
{
register int if_z=;now=;
register char Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int main()
{
in(n),in(m);int u,v;
for(int i=;i<=m;i++)
{
in(u),in(v);
edge[++cnt].v=v,edge[cnt].e=head[u],head[u]=cnt;
edge[++cnt].v=u,edge[cnt].e=head[v],head[v]=cnt;
}
for(int i=;i<=n;i++)
{
if(!if_[i])
{
int tot=,pos=;
queue<int>que;que.push(i),if_[i]=true;
while(!que.empty())
{
int now=que.front();que.pop();
for(int i=head[now];i;i=edge[i].e)
{
if(!if_[edge[i].v])
{
tot++;
que.push(edge[i].v);
if_[edge[i].v]=true;
dis[edge[i].v]=dis[now]^;
if(dis[now]) pos++;
}
else
{
if(dis[edge[i].v]==dis[now]) ifo=true;
}
}
}
ans+=min(tot-pos,pos);
}
}
if(ifo) cout<<"Impossible";
else cout<<ans;
return ;
}

AC日记——封锁阳光大学 洛谷 P1330的更多相关文章

  1. AC日记——[SDOI2015]星际战争 洛谷 P3324

    题目描述 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战. 在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai.当一个巨型机器人的装甲值 ...

  2. AC日记——联合权值 洛谷 P1351

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  3. AC日记——I Hate It 洛谷 P1531

    题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...

  4. AC日记——神奇的幻方 洛谷 P2615(大模拟)

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

  5. AC日记——[CQOI2009]DANCE跳舞 洛谷 P3153

    [CQOI2009]DANCE跳舞 思路: 二分+最大流: 代码: #include <cstdio> #include <cstring> #include <iost ...

  6. AC日记——松江1843路 洛谷七月月赛

    松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...

  7. AC日记——严酷的训练 洛谷 P2430

    严酷的训练 思路: 背包: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 5005 int n,m,bi[m ...

  8. AC日记——[SDOI2010]大陆争霸 洛谷 P3690

    [SDOI2010]大陆争霸 思路: dijkstra模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn ...

  9. AC日记——小魔女帕琪 洛谷 P3802

    小魔女帕琪 思路: 概率公式计算: 代码: #include <bits/stdc++.h> using namespace std; ],sig; int main() { ;i< ...

随机推荐

  1. pandas知识点(汇总和计算描述统计)

    调用DataFrame的sum方法会返还一个含有列的Series: In [5]: df = DataFrame([[1.4,np.nan],[7.1,-4.5],[np.nan,np.nan],[0 ...

  2. Compiler Error Message: CS0016: Could not write to output

    打开网页是报错: Server Error in '/' Application. Compilation Error Description: An error occurred during th ...

  3. poj 3104 晾衣服问题 最大化最小值

    题意:n件衣服各含有ai水分,自然干一分钟一个单位,放烘干机一分钟k个单位,问:最短时间? 思路: mid为最短时间 如果 a[i]-mid>0说明需要放入烘干机去烘干 烘干的时间为x  那么满 ...

  4. Android 有些机型hint不显示

    这个问题就是有些手机型号,hint字体正好和你的背景色一样,不如你的背景色是白色, 因为大多数的系统,hint都是灰色,所以可以显示,有些手机他妈的就是hint默认字体是白色,结果显示不出来. 那么就 ...

  5. How to check if Visual Studio 2005 SP1 is installed

    How to check if Visual Studio 2005 SP1 is installed Check the following registry key. HKEY_LOCAL_MAC ...

  6. Windows 2008 WinRM和WinRS能帮你做什么?

     介绍    WinRM及WinRS更新包含在Windows Vista, Windows Server 2003 R2, Windows Server 2008 (及 Server 2008 Cor ...

  7. 【Luogu P1661】扩散

    题目: 一个点每过一个单位时间就会向四个方向扩散一个距离,如图. 两个点$a$.$b$连通,记作$e(a,b)$,当且仅当$a$.$b$的扩散区域有公共部分.连通块的定义是块内的任意两个点$u$.$v ...

  8. Python+Selenium练习篇之1-摘取网页上全部邮箱

    前面已经介绍了Python+Selenium基础篇,通过前面几篇文章的介绍和练习,Selenium+Python的webUI自动化测试算是入门了.接下来,我计划写第二个系列:练习篇,通过一些练习,了解 ...

  9. 微信小程序-----校园头条整体概括

    1.项目需求 为了让在校师生可以更加方便的了解学校信息,从而合理的安排自己的时间,避免发生冲突和错过事件,通过小程序的便利性,可以达到随手一查的功能. 2.项目布局 3.效果展示 3.1登录 3.2首 ...

  10. python学习_常用语句

    1.变量 1 name='hu qihang' #变量名应为英文,方便阅读 2 name_of_gf='chen ye' #多个单词用下划线隔开 3 名字='hu qihang' #变量名可以是中文 ...