Gym100923H Por Costel and the Match
题目链接:http://codeforces.com/gym/100923/problem/H
分析:并查集,用enemy储存x的敌人,用weight储存权重决定根节点
需用scanf和puts输入输出否则会爆
1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<string> 6 #include<cstring> 7 #include<algorithm> 8 #include<functional> 9 #include<iomanip> 10 #include<numeric> 11 #include<cmath> 12 #include<queue> 13 #include<vector> 14 #include<set> 15 #include<cctype> 16 #define PI acos(-1.0) 17 const int INF = 0x3f3f3f3f; 18 const int NINF = -INF - 1; 19 const int maxn = 1e5 + 5; 20 typedef long long ll; 21 using namespace std; 22 int n, m; 23 int fa[maxn], enemy[maxn], weight[maxn]; 24 int find(int x) 25 { 26 return x == fa[x] ? x : fa[x] = find(fa[x]); 27 } 28 void unite(int x, int y) 29 { 30 if (weight[x] < weight[y]) fa[x] = y; 31 else 32 { 33 fa[y] = x; 34 if (weight[x] == weight[y]) weight[x]++; 35 } 36 } 37 int main() 38 { 39 //std::ios::sync_with_stdio(false); 40 freopen("meciul.in", "r", stdin); 41 freopen("meciul.out", "w", stdout); 42 int T; 43 scanf("%d", &T); 44 while (T--) 45 { 46 scanf("%d%d", &n, &m); 47 memset(enemy, 0, sizeof(enemy)); 48 memset(weight, 0, sizeof(weight)); 49 for (int i = 1; i <= n; ++i) fa[i] = i; 50 while (m--) 51 { 52 int x, y; 53 scanf("%d%d", &x, &y); 54 int f1 = find(x), f2 = find(y); 55 if (f1 == f2) puts("NO"); 56 else 57 { 58 if (!enemy[x]) enemy[x] = y; 59 else unite(f2, find(enemy[x])); 60 if (!enemy[y]) enemy[y] = x; 61 else unite(f1, find(enemy[y])); 62 puts("YES"); 63 } 64 } 65 } 66 return 0; 67 }
转载于:https://www.cnblogs.com/veasky/p/11282882.html
Gym100923H Por Costel and the Match相关推荐
- Por Costel and the Match Gym - 100923H(经典种类并查集)
Por Costel and the Match Gym - 100923H 题目链接:https://vjudge.net/problem/Gym-100923H 题目: Oberyn Martel ...
- Gym-100923H-Por Costel and the Match(带权并查集)
链接: https://vjudge.net/problem/Gym-100923H 题意: Oberyn Martell and Gregor Clegane are dueling in a tr ...
- I - Por Costel and the Pairs Gym - 100923I _思维啊——可惜我现在还没
We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did. The d ...
- CCPC-Wannafly Summer Camp 2019 全记录
// 7.19-7.29 东北大学秦皇岛校区十天训练营,题目都挂在了Vjudge上.训练期间比较忙,没空更博总结,回来继续补题消化. Day1 这天授课主题是简单图论,节奏挺好,wls两小时理完图论里 ...
- SCAU-春季训练-不应该啊(怎么这么菜。。。)
2021/3/14 春季训练2(难度div2d) 反思:(赛前,看什么crt,赛时满脑子都是线性方程组,....................................) 最近表现都不太好.. ...
- java 中showinfo方法,jmockito模拟方法中参数如何指定
在做单元测试的时候,经常会遇到mock类的方法的情景.在写单测过程中,遇到一些问题,比较困惑,便做了一些测试,并得出一个结论: 在mock类的方法时,当符合 (mock参数).equals(实际调用过 ...
- Not injecting HSTS header since it did not match the requestMatcher HSTS设置问题解决
HSTS请求设置 错误描述:在使用文件上传功能时,form表单提交带有header数据的请求时遇到这个问题,报错如下: Not injecting HSTS header since it did n ...
- python中的match和search的区别
对比 match(string[, pos[, endpos]]) | re.match(pattern, string[, flags]): 这个方法将从string的pos下标处起尝试匹配patt ...
- Python中re的match、search、findall、finditer区别正则
20210728 search 得到索引范围 原文地址: http://blog.csdn.net/djskl/article/details/44357389 这四个方法是从某个字符串中寻找特定子串 ...
最新文章
- 多路复用select和epoll的区别(转)
- Java论坛系统 JForum
- 人生苦短,我用python,为什么选择python,python简介
- 电话号码的判断--使用正则表达式的示例
- iOS 动画绘制线条颜色渐变的折线图
- oracle asm磁盘回收步骤,【翻译自mos文章】回收 asm磁盘空间的方法
- c语言键盘按f1显示f1,windows10键盘f1变成功能键的两种解决方法
- 第三十一章 考试作弊
- c#实现添加虚拟IP
- 本地图文直接复制到动易CMS编辑器中
- 洛谷P5708 【深基2.习2】三角形面积__C++描述
- Command rejected: Bad VLAN list
- [MATLAB]最邻近插值法进行图像放大
- 看看什么叫穿越失败,我承认我确实笑了
- html的几种选择器
- 【计算机网络】常见面试题总结
- 常喝酸奶,远离糖尿病
- 解决[“usingcomponents“][“van-button“]: “@vant/weapp/button/index“ 未找到:
- 3d Max安装失败(Microsoft Visual C++ 2010 Redistributable)
- 【业务】畅捷通T+销售业务分解操作指导
热门文章
- 无法将多信息文本转换为url_实体链接:信息抽取中的NLP的基础任务
- linux修改jdk文件保存,Linux下更换jdk和配置环境变量详解
- 聚类时需要标准化吗_收房时,需要请专业验房师吗?
- java 实体类属性排序_按照list中实体类的某一属性排序
- mysql 所有外键_mysql中的外键
- android jni示例_Android动画示例
- python oct_Python oct()
- Android CheckBox
- jsp错误处理页面_JSP异常处理– JSP错误页面
- AppBarLayout中的Android TabLayout