BZOJ 4579: [Usaco2016 Open]Closing the Farm
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的更多相关文章
- 【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 ...
- BZOJ 4576: [Usaco2016 Open]262144
Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...
- 【BZOJ 4579】【Usaco2016 Open】Closing the Farm
http://www.lydsy.com/JudgeOnline/problem.php?id=4579 把时间倒过来,只是加点,并查集维护连通块. #include<cstdio> #i ...
- 续并查集学习笔记——Closing the farm题解
在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...
- 一道并查集的(坑)题:关闭农场closing the farm
题目描述 in English: Farmer John and his cows are planning to leave town for a long vacation, and so FJ ...
- [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 ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- bzoj 4506: [Usaco2016 Jan]Fort Moo
4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...
随机推荐
- 从零开始HTML(一 2016/10/17)
就是准备跟着霹雳猿教程过一遍HTML啦,边看边记录更便于理解记忆吧~ 1.属性 HTML 标签可以拥有属性.属性提供了有关 HTML 元素的更多的信息.属性总是以名称/值对的形式出现,比如:name= ...
- 有关stdint.h 文件
有关stdint.h 文件 Google C++编程规范的P25页有如下叙述: <stdint.h> 定义了 int16_t . uint32_t . int64_t 等整型,在需要确定大 ...
- Occlusion Culling
遮挡剔除 http://www.bjbkws.com/online/1092/ unity遮挡剔除(应用) http://www.unitymanual.com/thread-37302-1-1.ht ...
- IP欺骗原理与过程分析
IP欺骗攻击法 原创:r00t <r00t@unsecret.org> QQ: 22664566 http://www.unsecret.org --------------------- ...
- 解决windows系统80端口被占用问题(转)
在windows下部署web应用(80端口),启动时提示bind 80端口失败 检查端口占用: netstat -ano | findstr 0.0.0.0:80 发现System进程 (pid=4) ...
- intelligencia.urlrewriter使用
见github: https://github.com/sethyates/urlrewriter
- spring 后置处理器BeanFactoryPostProcessor和BeanPostProcessor的用法和区别
主要区别就是: BeanFactoryPostProcessor可以修改BEAN的配置信息而BeanPostProcessor不能,下面举个例子说明 BEAN类: package com.spring ...
- android控件库(1)-带删除功能的EditText
DJEditText.java /** * Created by xp.chen on 2016/11/25. */ public class DJEditText extends AppCompat ...
- C语言strdup函数
static RD_INLINE RD_UNUSED char *rd_strdup(const char *s) { #ifndef _MSC_VER char *n = strdup(s); #e ...
- c# 中使用memcached
1.首先下载memcached 服务端 2.使用Enyim.Caching .Net 客户端 3.配置web.config <sectionGroup name="QuickBo ...