bzoj 3060[Poi2012]Tour de Byteotia 贪心+生成树
Description
给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上。
Analysis
包含关键点的环中
包含从关键点连出的两条边
考虑我们删边删哪些边更优
根据贪心
我们会删与关键点相连的边
一直删我们发现不会删掉不与关键点相连的边
Solution
于是我们先把边顶点都大于k的先连起来
相当于合并了一些点
在新的图里,每个连通块里都不能生成环
那最多保留一棵生成树
Solution
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <cmath>
using namespace std;
const int M=1000007;
inline int rd(){
int x=0;bool f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
for(;isdigit(c);c=getchar()) x=x*10+c-48;
return f?x:-x;
}
int n,m,k;
int f[M],hav[M];
struct node{
int x,y;
node(int xx=0,int yy=0){x=xx;y=yy;}
}ed[M<<1];
int te;
int find(int x){
return (f[x]==x)?x:(f[x]=find(f[x]));
}
int link(int x,int y){
x=find(x);y=find(y);
if(x!=y){
f[x]=y;
hav[y]=hav[x]|hav[y];
return 0;
}
return hav[x];
}
int main(){
int i,x,y,ans=0;
n=rd(),m=rd(),k=rd();
for(i=1;i<=n;i++) f[i]=i;
for(i=1;i<=k;i++) hav[i]=1;
for(i=1;i<=m;i++){
x=rd(),y=rd();
if(x>k&&y>k){
link(x,y);
}
else ed[++te]=node(x,y);
}
for(i=1;i<=te;i++)
ans+=link(ed[i].x,ed[i].y);
printf("%d\n",ans);
return 0;
}
bzoj 3060[Poi2012]Tour de Byteotia 贪心+生成树的更多相关文章
- BZOJ 3060: [Poi2012]Tour de Byteotia 并查集
前 $k$ 个节点形成的结构必定是森林,而 $[k+1,r]$ 之间肯定是都连上,而剩下的一个在 $[1,k],$一个在 $[k+1,r]$ 的节点就能连多少连多少即可. Code: #include ...
- Bzoj3060 [Poi2012]Tour de Byteotia
3060: [Poi2012]Tour de Byteotia Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 251 Solved: 161 Des ...
- 【BZOJ3060】[Poi2012]Tour de Byteotia 并查集
[BZOJ3060][Poi2012]Tour de Byteotia Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Input ...
- [bzoj3060][Poi2012]Tour de Byteotia_并查集
[Poi2012]Tour de Byteotia 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3060 题解: 这类题有一个套路,就是 ...
- [POI2012]Tour de Bajtocja
[POI2012]Tour de Bajtocja 题目大意: 给定一个\(n(n\le10^6)\)个点\(m(m\le2\times10^6)\)条边的无向图,问最少删掉多少条边能使得编号小于等于 ...
- 【[POI2012]TOU-Tour de Byteotia】
[[POI2012]TOU-Tour de Byteotia] 洛谷P3535 https://www.luogu.org/problemnew/show/P3535 JDOJ 2193旅游景点(同类 ...
- Bzoj 3624: [Apio2008]免费道路 (贪心+生成树)
Sample Input 5 7 2 1 3 0 4 5 1 3 2 0 5 3 1 4 3 0 1 2 1 4 2 1 Sample Output 3 2 0 4 3 0 5 3 1 1 2 1 这 ...
- bzoj 2792: [Poi2012]Well【二分+贪心】
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const ...
- BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心
BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心 Description 有一家专卖一种商品的店,考虑连续的n天. 第i天上午会进货Ai件商品,中午的时候会有顾客需要购买 ...
随机推荐
- hbuilder 夜神模拟器调试方法
1.首先下载好夜神模拟器2.查找已经安装的夜神模拟的端口,这里说一下夜神模拟器默认端口是62001,但是有些版本可能不是这个端口,怎么查找到底是哪个端口呢?按照如下顺序进行就可以查找到你按装的夜神模拟 ...
- skynet 学习笔记-sproto模块(2)
云风在skynet中继承了sproto的传输协议,对比protobuf的好处是,能明文看到传输内容,而且skynet不需要protobuf这么功能,所以云风也建议在lua层使用sproto来作为sky ...
- ubuntu 16.04 + 中文输入法
在桌面右上角设置图标中找到"System Setting",双击打开. 在打开的窗口里找到"Language Support",双击打开. 可能打开会说没有安装 ...
- 解决linux不能解压rar格式压缩包
1download rarlinux-x64-5.3.0.tar.gz data package 2.tar xvf rarlinux-64-5.3.0.tar.gz 3. cd rar and th ...
- mysql按指定顺序排序
select id,name from htms_center_freight_users where id in(114,112,91,223,134) order by find_in_set(i ...
- django知识分支_1
django知识分支 1.Cookie工作流程: 浏览器向服务器发出请求,服务器接收到浏览器的请求进行处理,服务器设置一个cookie发送给浏览器,浏览器将cookie保存,当需要再次登录的时候,浏览 ...
- Python9-网络编程3-day32
解决黏包的问题 #server import socket sk = socket.socket() sk.bind(('127.0.0.1',8080)) sk.listen() conn,addr ...
- Android内核编译步骤
android_4.0.4_tq210$ source build/envsetup.shandroid_4.0.4_tq210$ lunch 5/android_4.0.4_tq210$ make ...
- 解决VMware vSphere Client无法连接ESXi虚拟主机方法
1 一般情况下重启services.sh就可以解决(或图形界面下restart management agent)services.sh restart2 若重启services.sh报错且仍然无法连 ...
- bash 统计在线时长最长的十个玩/统计一天内一直处于不活跃状态的玩家的百分比
1.某游戏的客户端每隔5分钟会向服务端报告一次玩家的账户积分,如果两次报告的时间间隔不大于5分钟,认为该玩家在这5分钟内在线,假设报告数据的格式如下: IP Dat ...