Zjnu Stadium HDU - 3047 带权并查集板子题
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- using namespace std;
- const int N=+;
- int p[N];
- int w[N];
- int find(int x)
- {
- if(p[x]==x)
- return x;
- int root=find(p[x]);
- w[x]+=w[p[x]];
- p[x]=root;
- return p[x];
- }
- int n,m;
- int main()
- {
- while(~scanf("%d%d",&n,&m))
- {
- for(int i=;i<=n;i++)
- p[i]=i,w[i]=;
- int ans=;
- for(int i=;i<=m;i++)
- {
- int a,b,c;
- scanf("%d%d%d",&a,&b,&c);
- int pa=find(a);
- int pb=find(b);
- if(pa==pb)
- {
- if(w[a]+c!=w[b])
- ans++;
- }
- else
- {
- p[pb]=pa;
- w[pb]=w[a]-w[b]+c;
- }
- }
- printf("%d\n",ans);
- }
- return ;
- }
Zjnu Stadium HDU - 3047 带权并查集板子题的更多相关文章
- 【poj 1962】Corporative Network(图论--带权并查集 模版题)
P.S.我不想看英文原题的,但是看网上题解的题意看得我 炒鸡辛苦&一脸懵 +_+,打这模版题的代码也纠结至极了......不得已只能自己翻译了QwQ . 题意:有一个公司有N个企业,分成几个网 ...
- HDOJ 3047 带权并查集
解题思路转自: http://blog.csdn.net/azheng51714/article/details/8500459 http://blog.csdn.net/acresume/artic ...
- HDU - 3038 带权并查集
这道题我拖了有8个月... 今天放假拉出来研究一下带权的正确性,还有半开半闭的处理还有ab指向的一系列细节问题 #include<iostream> #include<algorit ...
- hdu 3038带权并查集
#include<stdio.h> #include<string.h> #define N 200100 struct node { int x,count; }pre[N ...
- hdu 1829 带权并查集的运用类似于食物链但是更简单些
#include<stdio.h> #define N 1100000 struct node { int x,y; }f[N],pre[N]; int find(int x) { if( ...
- K - Find them, Catch them POJ - 1703 (带权并查集)
题目链接: K - Find them, Catch them POJ - 1703 题目大意:警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<= ...
- poj1417(带权并查集+背包DP+路径回溯)
题目链接:http://poj.org/problem;jsessionid=8C1721AF1C7E94E125535692CDB6216C?id=1417 题意:有p1个天使,p2个恶魔,天使只说 ...
- poj1182(带权并查集)
题目链接:http://poj.org/problem?id=1182 题意:题目告诉有 3 种动物,互相吃与被吃,现在告诉你 m 句话,其中有真有假,叫你判断假的个数 ( 如果前面没有与 ...
- [NOI2002] 银河英雄传说 (带权并查集)
题目描述 公元五八○一年,地球居民迁至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰山压顶 ...
随机推荐
- 《自拍教程9》Python编程风格规范
Python编程风格规范 根据Python官方提供的Python编程风格规范: Style Guide for Python Code, 即PEP8规范, https://www.python.org ...
- windows socket ipv6 SOCK_RAW
bind处一直报错WSAEADDRNOTAVAIL10049,不知道为什么? WSAEADDRNOTAVAIL 10049 Cannot assign requested address. The r ...
- Prometheus监控k8s集合
Prometheus监控k8s Prometheus监控k8s(1)-Prometheus简介 Prometheus监控k8s(2)-手动部署Prometheus Prometheus监控k8s(3) ...
- 使用FIO工具测试块存储性能
Linux实例和Windows实例都推荐使用FIO工具测试块存储性能. 说明 您也可以使用其他工具测试块存储性能,但不同工具测试出来的硬盘基准性能会有差异,如dd.sysbench.iometer ...
- 一键安装MySQL5.6.43脚本
[root@lamp ~]# cat /server/scripts/mysql-5.6.43_install.sh #!/bin/bash #卸载系统自带的Mysql /bin/rpm -e $(/ ...
- Windows+Python+Selenium基础篇之1-环境搭建
1.所需工具包1.1Selenium for python1.2 Python 1.3 Notepad++或python IDE 2. 环境搭建2.1 下载和安装Pythonpython2. ...
- vue-cli项目传到服务器后打不开的问题
1.vue-cli项目执行dev可以打开网站,直接点击文件或发布后却打不开的问题 webpack.prod.conf.js: output: { ....... publicPath:'./' ...
- A——大整数加法(HDU1002)
题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...
- toj 3019 Hidden Password (最小表示法)
Hidden Password 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交: 53 测试通过: 19 描述 Some time the progr ...
- Nginx Rewrite相关功能
目录 Nginx Rewrite相关功能 ngx_http_rewrite_module模块指令: if指令: set指令: break指令: return指令: rewrite_log指令: rew ...