GYM 101149 I.It's the Police(水~)
来源:互联网 发布:单词社交网络 网盘 编辑:程序博客网 时间:2024/05/01 01:43
Description
给出一n个点的无向图,要在一些点上放警察,一个点放警察那么这个点的邻接点都会被观察到,问在保证有一个点观察不到的情况下最多能放多少警察
Input
第一行两整数n和m分别表示点数和边数,之后m行每行两整数u,v表示u和v之间有一条边,无重边(1<=n<=2e5,0<=m<=2e5)
Output
输出n个01表示第i个点是否放警察
Sample Input
5 5
1 2
2 3
3 4
4 5
5 1
Sample Output
0 0 1 1 0
Solution
找出度最小的点让它和其邻接点都不放警察即为最优
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 222222int n,m,ans[maxn];vector<int>g[maxn];int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++)g[i].clear(); while(m--) { int u,v; scanf("%d%d",&u,&v); g[u].push_back(v),g[v].push_back(u); } int u=1; for(int i=2;i<=n;i++) if(g[i].size()<g[u].size())u=i; for(int i=1;i<=n;i++)ans[i]=1; ans[u]=0; for(int i=0;i<g[u].size();i++)ans[g[u][i]]=0; for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' '); } return 0;}
0 0
- GYM 101149 I.It's the Police(水~)
- Gym 101149IIt's the Police 图+简单遍历
- China's battle to police the web
- GYM 100694 I.Goat in the Field(水~)
- GYM 101147 I.On the way to the park(水~)
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
- GYM 100285 I. The old Padawan(二分+简单模拟)
- VMware vSphere “I moved it” or “I copied it” – What’s the difference?
- GYM 100488 I.Map Coloring(水~)
- GYM 101102 I.Simple Robot(水~)
- Gym 100703M It's complicated 水题
- GYM 101149 E.The Best among Equals(水~)
- GYM 101149 F.The Weakest Sith(水~)
- The police and cooker
- hdu5742 It's All In The Mind(水)
- gym I. Painting the natural numbers
- It's the beginning
- It's the chance~!
- 校园地图
- 各个行业分类标准
- 【bzoj4034】[HAOI2015]T2
- 四.文件自校验大小破解(GetFileSize)
- PAT-A 1029. Median (25)
- GYM 101149 I.It's the Police(水~)
- codeforces 791B
- 程序小白该,如何从零开始学Java编程?
- leetcode82~Remove Duplicates from Sorted List II
- 【知识库】--mysql engines MyISAM vs InnoDB(146)
- Hello,World!
- 你好
- 愿天下有情人都是失散多年的兄妹
- : AH00436: No installed service named "Apache2.4".