当前位置:网站首页>【集训DAY13】Internet【并查集】
【集训DAY13】Internet【并查集】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们发现每次修理后只需要一个并查集就可以把相连的连上。
c o d e code code
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const int MAXN = 1010;
int n, d, fa[MAXN];
struct node {
int x, y;
}a[MAXN];
bool v[MAXN];
double dis(int x, int y) {
return sqrt((a[x].x - a[y].x) * (a[x].x - a[y].x) * 1.0 + (a[x].y - a[y].y) * (a[x].y - a[y].y) * 1.0);
}
int getfa(int x) {
if(x == fa[x]) return x;
return fa[x] = getfa(fa[x]);
}
int main() {
scanf("%d%d", &n, &d);
for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i].x, &a[i].y), fa[i] = i;
char ch;
int x, y;
scanf("%c", &ch);
while(scanf("%c", &ch) != EOF) {
if(ch == 'O') {
scanf("%d", &x);
v[x] = 1;
for(int i = 1; i <= n; i ++) {
if(v[i] && dis(x, i) <= d * 1.0) {
int xx = getfa(x), yy = getfa(i);
if(xx == yy) continue;
fa[xx] = yy;
}
}
}
else {
scanf("%d%d", &x, &y);
if(!v[x] || !v[y]) {
printf("FAIL\n");
scanf("%c", &ch);
continue;
}
int xx = getfa(x), yy = getfa(y);
if(xx == yy) printf("SUCCESS\n");
else printf("FAIL\n");
}
scanf("%c", &ch);
}
return 0;
}
边栏推荐
- xss-工具-Beef-Xss安装以及使用
- H5幸运刮刮乐抽奖 免公众号+直运营
- Why is the integer type 128 to byte -128
- It's over. I went to work for three months and became bald
- SQL基本语句 DQL select与提取 DML插入删除
- C语言逆序打印字符串的两种方法
- 分享两个音乐播放地址
- How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
- 如何将一个域名解析到多个IP地址?
- Xiaobai programmer's seventh day
猜你喜欢
随机推荐
分享两个音乐播放地址
6-17 vulnerability exploitation - deserialization remote command execution vulnerability
沃达德软件:智慧城市方案
淦,为什么 '𠮷𠮷𠮷' .length !== 3 ??
聚名十年,说出你的故事,百万豪礼等你拿
分割金条的代价
微信发卡小程序源码-自动发卡小程序源码-带流量主功能
Minor GC 和 Full GC 有什么不同呢?
(1) Integrating two mapping frameworks of Dao
Visitor mode
(1) DDL, DML, DQL, DCL and common data types
力矩电机控制基本原理
El expression improves JSP
vim用法记录
【C语法】void*浅说
Compile and decompile
TFrecord写入与读取
MySQL --- 子查询 - 列子查询(多行子查询)
H5幸运刮刮乐抽奖 免公众号+直运营
C语言逆序打印字符串的两种方法









