传送门

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

——代码

 #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 ;
}

最新文章

  1. 如何向新手程序员介绍Java编程
  2. SDRAM读写一字(下)
  3. Support for Xpm library: no问题
  4. time元素
  5. 谷歌验证 (Google Authenticator) 的实现原理是什么?
  6. hdu1171
  7. PHP面试题之文件目录操作
  8. bootstrap注意事项(六)按钮
  9. 杭电oj A + B Again
  10. Redis14--jedis实现主从模式。
  11. 点评阿里JAVA手册之MySQL数据库 (建表规约、索引规约、SQL语句、ORM映射)
  12. 可选参数、命名参数、.NET的特殊类型、特性
  13. 100 - k8s源码分析-准备工作
  14. mac下chrome 长截图(不使用插件)
  15. Php中的goto用法
  16. vb.net
  17. (最详细)小米Note 2的usb调试模式在哪里开启的教程
  18. docker下运行labview2010
  19. C#中关于as关键字的使用
  20. mysql不存在插入否则更新

热门文章

  1. B1068 [SCOI2007]压缩 区间dp
  2. poj3463 Sightseeing——次短路计数
  3. bzoj2253
  4. SpringBoot 启动定时任务
  5. 9.10NOIP模拟题
  6. codevs3162抄书问题(划分型dp)
  7. Hadoop Hive概念学习系列之hive里的桶(十一)
  8. 自己整理的css3动画库,附下载链接
  9. 这辈子写过的比较有意思的几个sql
  10. 简单TCP代码