Description

依次删去一个点和它的边,问当前图是否连通.

Sol

并查集.

倒着做就可以了.

每次将一个点及其的边加入,如果当前集合个数大于 1,那么就不连通.

Code

/**************************************************************
Problem: 4579
User: BeiYu
Language: C++
Result: Accepted
Time:2196 ms
Memory:10328 kb
****************************************************************/ #include <cstdio>
#include <vector>
#include <iostream>
using namespace std; const int N = 200050; int n,m,cs;
int b[N],p[N],f[N],ans[N];
vector< int > g[N]; inline int in(int x=0){ scanf("%d",&x);return x; }
int find(int x){ return f[x] == x ? x : f[x]=find(f[x]); }
int main(){
n=in(),m=in();
for(int i=1,u,v;i<=m;i++){
u=in(),v=in();
g[u].push_back(v),g[v].push_back(u);
}
for(int i=1;i<=n;i++) p[i]=in();
for(int i=1;i<=n;i++) f[i]=i; for(int x=n,u,v;x;--x){
cs++;
u=p[x],b[u]=1;
for(int i=0,lim=g[u].size();i<lim;i++){
v=g[u][i];
if(b[v]) if(find(u) != find(v)) f[find(u)]=find(v),cs--;
}
if(cs > 1) ans[x]=0;else ans[x]=1;
}
for(int i=1;i<=n;i++) if(ans[i]) puts("YES");else puts("NO");
return 0;
}

  

BZOJ 4579: [Usaco2016 Open]Closing the Farm的更多相关文章

  1. 【bzoj4579】[Usaco2016 Open]Closing the Farm 并查集

    题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...

  2. BZOJ 4576: [Usaco2016 Open]262144

    Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...

  3. 【BZOJ 4579】【Usaco2016 Open】Closing the Farm

    http://www.lydsy.com/JudgeOnline/problem.php?id=4579 把时间倒过来,只是加点,并查集维护连通块. #include<cstdio> #i ...

  4. 续并查集学习笔记——Closing the farm题解

    在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...

  5. 一道并查集的(坑)题:关闭农场closing the farm

    题目描述 in English: Farmer John and his cows are planning to leave town for a long vacation, and so FJ ...

  6. [USACO16OPEN]关闭农场Closing the Farm(洛谷 3144)

    题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...

  7. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

  8. BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 491  S ...

  9. bzoj 4506: [Usaco2016 Jan]Fort Moo

    4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...

随机推荐

  1. win8启动文件夹

    进入C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp.鼠标右键选中粘贴,将软件快捷方式粘贴到启动目录 进入文件夹时路径可能是C: ...

  2. centos设置编码

    CentOS6.5解决中文乱码与设置字符集 Windows的默认编码为GBK,Linux的默认编码为UTF-8.在Windows下编辑的中文,在Linux下显示为乱码.为了解决此问题,修改Linux的 ...

  3. SQL 使用小记

    1. case语句 示例 select id, name, case user_role then "管理员" then "未注册用户" then " ...

  4. Podfile升级后的影响

    之前项目里用的Podfile都是版本 0.39 后面有一天电脑格盘重装以后cocoapods装的版本是 1.0.0.beta.6 那么问题来了,在下载或者clone一下项目后,经常是需要自己安装第三方 ...

  5. 数据库操作事务IsolationLevel 枚举

      成员名称 说明   Chaos 无法覆盖隔离级别更高的事务中的挂起的更改.   ReadCommitted 在正在读取数据时保持共享锁,以避免脏读,但是在事务结束之前可以更改数据,从而导致不可重复 ...

  6. thinkphp 3.2 视图模型 实例 视图查询结果 二维数组 合并

    使用视图模型查询的时候 结果是这样的 array(6) { [0] => array(5) { ["picTitle"] => string(7) "标题2& ...

  7. VIP卡

    VIP卡:http://item.taobao.com/item.htm?id=6826715667&ali_refid=a3_420435_1006:1102617497:6::683ff3 ...

  8. Redis 资源

    一.资源 1.Redis中文网站: http://www.redis.cn/ 2.RedisDesktop http://redisdesktop.com/download

  9. js字符串转成数字的三种方法

    js读取的html代码中获得的值 ,统统是以字符串的形式呈现的,为了方便我们后面对数据的操作,有时候我们有必要进行转换一下. 方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转 ...

  10. html中的 button,input-button, image, input-image的区别

    hmtl中 为了验证 form的 action提交属性, 是指 表单提交到的 页面, 可以是任意 性质的页面, 如:html页面, php页面, asp页面等都可以, 实际在测试的时候, 可以就写 提 ...