[HDU3038]How Many Answers Are Wrong(并查集)
和某题类似,只不过奇偶换成了和。
——代码
#include <cstdio>
#include <iostream>
#define N 1000001 int n, m, ans;
int f[N], d[N]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline int find(int x)
{
if(x ^ f[x])
{
int fx = f[x];
f[x] = find(f[x]);
d[x] += d[fx];
}
return f[x];
} int main()
{
int i, x, y, z, fx, fy;
while(~scanf("%d %d", &n, &m))
{
ans = ;
for(i = ; i <= n; i++) f[i] = i, d[i] = ;
for(i = ; i <= m; i++)
{
x = read() - ;
y = read();
z = read();
fx = find(x);
fy = find(y);
if(fx == fy)
{
if((d[x] - d[y]) ^ z) ans++;
}
else
{
d[fx] = d[y] - d[x] + z;
f[fx] = fy;
}
}
printf("%d\n", ans);
}
return ;
}
[HDU3038]How Many Answers Are Wrong(并查集)的更多相关文章
- HDU3038 How Many Answers Are Wrong 并查集
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU3038 题意概括 有一个序列,共n个数,可正可负. 现在有m个结论.n<=200000,m< ...
- HDU 3038 How Many Answers Are Wrong (并查集)
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 3038 How Many Answers Are Wrong (并查集)---并查集看不出来系列-1
Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad b ...
- HDU 3038 How Many Answers Are Wrong 并查集带权路径压缩
思路跟 LA 6187 完全一样. 我是乍一看没反应过来这是个并查集,知道之后就好做了. d[i]代表节点 i 到根节点的距离,即每次的sum. #include <cstdio> #in ...
- HDU3038 How Many Answers Are Wrong[带权并查集]
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu3038 How many answers are wrong【并查集】
TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always w ...
- HDU3038 How Many Answers Are Wrong —— 带权并查集
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 200 ...
- 【HDU3038】How Many Answers Are Wrong - 带权并查集
描述 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always ...
- 【带权并查集】【HDU3038】【How Many Answers Are Wrong】d s
这个题看了2天!!!最后看到这篇题解才有所明悟 转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html ---by 墨染之樱 ...
- hdu3038 How Many Answers Are Wrong【基础种类并查集】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html ---by 墨染之樱花 题目链接:http://acm.hdu.ed ...
随机推荐
- P2657 [SCOI2009]windy数 数位dp
数位dp之前完全没接触过,所以NOIP之前搞一下.数位dp就是一种dp,emm……用来求解区间[L,R]内满足某个性质的数的个数,且这个性质与数的大小无关. 在这道题中,dp[i][j]代表考虑了i位 ...
- CF19 E Fairy——树上差分
题目:http://codeforces.com/contest/19/problem/E 先把图连成一棵树,然后对于每条非树边,判断它是在奇环中还是偶环中: 把环上的点打上相应的差分标记,并记录有多 ...
- windows 多mysql 实例
- Mac上随时切换PYTHON版本
在MAC上,默认安装了python2.*,自己又安装了python3.*:假如我们需要在终端上随时切换python控制台到需要的版本,可以采用下面的方法. 1.用命令 sudo vi ~/.bas ...
- what is success?
什么是成功?这是个老话题了.然而每个人对成功的认识却也不同.记得央视主持人王志说过成功是相对的,每个人都有自己的成功标准.有的人认为有钱.有房.有车.有女人,就是成功.有的人则认为成功是你做了一件你想 ...
- 【转】Linux下使用locale命令设置语言环境
转自:http://www.cnblogs.com/dolphi/p/3622570.html locale命令设置语言环境 在Linux中通过locale来设置程序运行的不同语言环境,locale由 ...
- IIS 503 错误
今天早上乘公交的时候,网站运维群里直接炸了,网站打不开,503错误.然后就各种@我,吓得我手机都要扔了,然后马不停蹄的赶往公司去查看错误. 我首先在IIS上浏览网页,想试图在服务器上显现出详细错误,这 ...
- Android Thermal-engine
Thermal Engine Thermal 相关的东西主要在Vendor/qcom/proprietary/thermal-engine 目录下: thermal-engine.conf 文件可以用 ...
- Ajax——异步基础知识(一)
基础概念 1.异步请求可以做到偷偷向服务器发送请求,而页面却不刷新 2.get异步请求传递参数是通过url追加键值对的方式 3.post异步请求比较特殊,需要设置请求的类型 User-Agent:浏览 ...
- mysql幻读
开启a,b两个数据库连接,a.b都开启事务后,b插入了一条数据R并提交,验证对a的操作造成的影响 select select for update update R update R 后 select ...