Tyvj P2044 ["扫地"杯III day2]旅游景点
2024-08-22 15:02:25
二次联通门 : 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 ;
}
最新文章
- Windows Phone 十九、罗盘
- unity, 顶点对齐
- git学习相关资料
- linux 网络协议分析---3
- AutoCAD使用技巧
- Hyper-V网络配置
- js深入研究之牛逼的类封装设计
- Javascript设计模式系列三
- HTML笔记<;note2>;
- ActiveMQ 入门
- Windows无人值守文件unattend制作以及自定义系统安装
- Luogu4916 魔力环 莫比乌斯反演、组合、生成函数
- 一个友盟BUG的思考和分析:Invalid update
- C#基础知识回顾-- 反射(2)
- 转---单页面应用下的JS内存管理
- scipy模块
- HTML 表格标签
- MySQL decimal unsigned 更新负数不报错却为0
- postgresql双机热备、高可用方案(采用pacemaker+corosync实现)
- mvc html.PartialView()传参
热门文章
- IDEA远程DEBUG Tomcat配置
- SpringBoot 常用配置 静态资源访问配置/内置tomcat虚拟文件映射路径
- 未能加载文件或程序集system.web.extensions解决方法
- asp.net core 一个中小型项目实战的起手式——Swagger配置
- 网络编程-tcp三次握手和四次挥手
- 如何把前端用ajax发过来的图片传到node上,并且用node保存在oss图片服务器上?
- JavaScript的变量和常量
- plsql developer中如何设置sql window显示行号
- ";Oracle要对Java收费了,SAP基于Java技术栈的那些产品的客户怎么办";
- python接口自动化11-post传data参数案例