TT and FF are ... friends. Uh... very very good friends -________-b

FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of integers-_-!!(bored).

Then, FF can choose a continuous subsequence from it(for example the subsequence from the third to the fifth integer inclusively). After that, FF will ask TT what the sum of the subsequence he chose is. The next, TT will answer FF's question. Then, FF can redo this process. In the end, FF must work out the entire sequence of integers.

Boring~~Boring~~a very very boring game!!! TT doesn't want to play with FF at all. To punish FF, she often tells FF the wrong answers on purpose.

The bad boy is not a fool man. FF detects some answers are incompatible. Of course, these contradictions make it difficult to calculate the sequence.

However, TT is a nice and lovely girl. She doesn't have the heart to be hard on FF. To save time, she guarantees that the answers are all right if there is no logical mistakes indeed.

What's more, if FF finds an answer to be wrong, he will ignore it when judging next answers.

But there will be so many questions that poor FF can't make sure whether the current answer is right or wrong in a moment. So he decides to write a program to help him with this matter. The program will receive a series of questions from FF together with the answers FF has received from TT. The aim of this program is to find how many answers are wrong. Only by ignoring the wrong answers can FF work out the entire sequence of integers. Poor FF has no time to do this job. And now he is asking for your help~(Why asking trouble for himself~~Bad boy)
InputLine 1: Two integers, N and M (1 <= N <= 200000, 1 <= M <= 40000). Means TT wrote N integers and FF asked her M questions.

Line 2..M+1: Line i+1 contains three integer: Ai, Bi and Si. Means TT answered FF that the sum from Ai to Bi is Si. It's guaranteed that 0 < Ai <= Bi <= N.

You can assume that any sum of subsequence is fit in 32-bit integer.
OutputA single line with a integer denotes how many answers are wrong.Sample Input

10 5
1 10 100
7 10 28
1 3 32
4 6 41
6 6 1

Sample Output

1

带权并查集的裸题

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000000007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int fa[];
int v[];
inline int getfa(int x)
{
if (fa[x]==x)return x;
else
{
int f=fa[x];
fa[x]=getfa(fa[x]);
v[x]+=v[f];
return fa[x];
}
}
int n,m,ans;
int main()
{
while (~scanf("%d%d",&n,&m))
{
ans=;
for (int i=;i<=n;i++)fa[i]=i,v[i]=;
for (int i=;i<=m;i++)
{
int x=read()-,y=read(),s=read();
int fx=getfa(x),fy=getfa(y);
if (fx==fy)
{
if (s!=v[x]-v[y])ans++;
continue;
}
fa[fx]=fy;v[fx]=v[y]-v[x]+s;
}
printf("%d\n",ans);
}
}

hdu 3038

最新文章

  1. caffe调试小结2
  2. iOS UITableViewCell的&quot;滑动出现多个按钮&quot;
  3. android小知识之fragment中调用startActivityForResult(Intent intent,int requestcode)所遇到的问题
  4. LeetCode OJ--Swap Nodes in Pairs
  5. HDU 5101 Select --离散化+树状数组
  6. HDU 1671 Phone List(字符处理)
  7. JsRender系列demo(3)-自定义容器
  8. P2184 贪婪大陆
  9. 小白鼓捣GIT的心得
  10. Hibernate 系列教程15-一级缓存
  11. 不能直接获取?聊聊如何在Shader Graph中获取深度图
  12. shelve 模块
  13. openvpn显示连接成功但是无法进行git操作
  14. onload、onpageshow、onpagehide、onbeforeunload、onunload的谣言纠正及特点介绍
  15. 20155334 曹翔 Exp2 后门原理与实践
  16. Lodop客户端本地和集中打印 [是否安装][操作系统]
  17. 抽象 abstract 和 接口 interface。 java 的 堆 和 栈。 参数传递(基本类型和普通对象的区别)
  18. C++中class的类型转换重载
  19. hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1
  20. vue2.* 环境搭建01

热门文章

  1. ThreadLocal应用场景以及源码分析
  2. Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: org.apache.http.entity.ContentType.withCharset(Ljava/lang/String;)Lorg/apache/http/entity/ContentType;
  3. 如何让Sublime Text编辑器支持新的ABAP关键字
  4. java 核心技术卷一笔记 6 .2接口 lambda 表达式 内部类
  5. Koa -- 基于 Node.js 平台的下一代 web 开发框架 koa.bootcss.com
  6. 修改visual studio setup 安装顺序(解决新版安装包无法自动移除老版本程序的问题)
  7. 业务系统中最核心的状态设计,异常 case. (系统设计)
  8. shell脚本调试打印日志问题
  9. iOS 高效 Mac 配置
  10. vs code背景图片的设置