传送门

某题类似,只不过奇偶换成了和。

——代码

 #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(并查集)的更多相关文章

  1. HDU3038 How Many Answers Are Wrong 并查集

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU3038 题意概括 有一个序列,共n个数,可正可负. 现在有m个结论.n<=200000,m< ...

  2. 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 ...

  3. 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 ...

  4. HDU 3038 How Many Answers Are Wrong 并查集带权路径压缩

    思路跟 LA 6187 完全一样. 我是乍一看没反应过来这是个并查集,知道之后就好做了. d[i]代表节点 i 到根节点的距离,即每次的sum. #include <cstdio> #in ...

  5. HDU3038 How Many Answers Are Wrong[带权并查集]

    How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. 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 ...

  7. HDU3038 How Many Answers Are Wrong —— 带权并查集

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 200 ...

  8. 【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 ...

  9. 【带权并查集】【HDU3038】【How Many Answers Are Wrong】d s

    这个题看了2天!!!最后看到这篇题解才有所明悟 转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html   ---by 墨染之樱 ...

  10. hdu3038 How Many Answers Are Wrong【基础种类并查集】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html   ---by 墨染之樱花 题目链接:http://acm.hdu.ed ...

随机推荐

  1. Java Swing Action 动作

    Swing包提供了一种非常实用的机制来封装命令,并将它们连接到多个事件源,这就是Action接口.一个动作是一个封装下列内容的对象: × 命令的说明(一个文本字符串和一个可选图标): × 执行命令所需 ...

  2. CentOS7 iso封装语句

    mkisofs -o /srv/neutron-controller.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot - ...

  3. mkisofs

    createrepo -g /enp/comps.xml . yum -y --downloadonly --downloaddir=/enp/Packages upgrade mkisofs -o ...

  4. Visual Studio Code配置GitHub(Win7环境)

    一.软件环境说明(演示环境) 1.操作系统:Windows7旗舰版(64bit) 2.Visual Studio Code版本:1.32.3 3.Git版本:2.21.0.windows.1 二.软件 ...

  5. Python3安装Scrapy

     Microsoft Visual C++ Build Tools 最近项目在写爬虫,项目经理给了个Python Scrapy的爬虫项目,要求使用Java实现相关功能.于是乎在本地先后安装了Pytho ...

  6. 【Codeforces1109B_CF1109B】Sasha and One More Name(字符串)

    题目: Codeforces1109B 我打的是 Div2 ,所以我看到的题号实际上是 1113D -- 考场上傻了没敢大力猜结论没做出来这道题,不幸掉分-- 1869->1849 嘤嘤嘤 翻译 ...

  7. 传值:web.xml传递参数 即在Servlet中获取web.xml里的值

    传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...

  8. MVC系列学习(十七)-过滤器

    本次学习的文件结构如下 1.过滤器的几种表示方式 1.1将过滤器 加到方法上,作用范围为该方法 1.2将过滤器加到当前类上,作用范围为该类的所有方法 1.3添加全局过滤器,作用范围为所有方法 2.Ac ...

  9. D3.js 力导向图(小气泡围绕中心气泡)

    html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3 ...

  10. CWnd* pParent

    Dlg(CWnd* pParent = NULL)的意思是:构造函数.创建对象时第一个调用的地方.CWnd* pParent=NULL是构造的参数,可以不传入,默认为NULL 构造函数(constru ...