二次联通门 : Tyvj P2044 ["扫地"杯III day2]旅游景点

/*
Tyvj P2044 ["扫地"杯III day2]旅游景点 并查集
先把大于K的点合并
再从头扫一遍
若当前边的两边不在同一个集合就合并
否则就割掉这条边
*/
#include <cstdio>
#include <iostream> const int BUF = ;
char Buf[BUF], *buf = Buf; inline void read (int &now)
{
for (now = ; !isdigit (*buf); ++ buf);
for (; isdigit (*buf); now = now * + *buf - '', ++ buf);
} #define Max 100009
struct E { int u, v; };
int f[Max]; E e[Max << ];
int Find (int x) { return f[x] == x ? x : f[x] = Find (f[x]); } int main (int argc, char *argv[])
{
freopen ("1.in", "r", stdin); fread (buf, , BUF, stdin);
int N, M, K, x, y, Answer = ; register int i, j;
read (N), read (M), read (K);
for (i = ; i <= N; ++ i) f[i] = i;
for (i = ; i <= M; ++ i)
{
read (e[i].u), read (e[i].v);
if (e[i].u > K && e[i].v > K)
{
x = Find (e[i].u), y = Find (e[i].v);
f[x] = f[y];
}
}
for (i = ; i <= M; ++ i)
{
if (e[i].u > K && e[i].v > K) continue;
x = Find (e[i].u), y = Find (e[i].v);
if (x != y) f[x] = y;
else ++ Answer;
}
printf ("%d", Answer);
return ;
}

最新文章

  1. Windows Phone 十九、罗盘
  2. unity, 顶点对齐
  3. git学习相关资料
  4. linux 网络协议分析---3
  5. AutoCAD使用技巧
  6. Hyper-V网络配置
  7. js深入研究之牛逼的类封装设计
  8. Javascript设计模式系列三
  9. HTML笔记&lt;note2&gt;
  10. ActiveMQ 入门
  11. Windows无人值守文件unattend制作以及自定义系统安装
  12. Luogu4916 魔力环 莫比乌斯反演、组合、生成函数
  13. 一个友盟BUG的思考和分析:Invalid update
  14. C#基础知识回顾-- 反射(2)
  15. 转---单页面应用下的JS内存管理
  16. scipy模块
  17. HTML 表格标签
  18. MySQL decimal unsigned 更新负数不报错却为0
  19. postgresql双机热备、高可用方案(采用pacemaker+corosync实现)
  20. mvc html.PartialView()传参

热门文章

  1. IDEA远程DEBUG Tomcat配置
  2. SpringBoot 常用配置 静态资源访问配置/内置tomcat虚拟文件映射路径
  3. 未能加载文件或程序集system.web.extensions解决方法
  4. asp.net core 一个中小型项目实战的起手式——Swagger配置
  5. 网络编程-tcp三次握手和四次挥手
  6. 如何把前端用ajax发过来的图片传到node上,并且用node保存在oss图片服务器上?
  7. JavaScript的变量和常量
  8. plsql developer中如何设置sql window显示行号
  9. &quot;Oracle要对Java收费了,SAP基于Java技术栈的那些产品的客户怎么办&quot;
  10. python接口自动化11-post传data参数案例