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

hdu3038 How Many Answers Are Wrong的更多相关文章

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

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

  2. HDU3038 How Many Answers Are Wrong 并查集

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

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

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

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

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

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

  6. hdu3038 How Many Answers Are Wrong 种类并查集

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ...

  7. [HDU3038]How Many Answers Are Wrong(并查集)

    传送门 和某题类似,只不过奇偶换成了和. ——代码 #include <cstdio> #include <iostream> #define N 1000001 int n, ...

  8. HDU-3038 How Many Answers Are Wrong(带权并查集区间合并)

    http://acm.hdu.edu.cn/showproblem.php?pid=3038 大致题意: 有一个区间[0,n],然后会给出你m个区间和,每次给出a,b,v,表示区间[a,b]的区间和为 ...

  9. OI 刷题记录——每周更新

    每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余 ...

随机推荐

  1. 将sql 查询结果导出到excel

    在平时工作中经常会遇到,sql 查询数据之后需要发送给业务人员,每次都手工执行脚本然后拷贝数据到excel中,比较耗时耗力,可以考虑自动执行查询并将结果邮件发送出来. 分两步实现: 1.执行查询将结果 ...

  2. SQLite - WHERE子句

    SQLite - WHERE子句 SQLite WHERE子句用于指定一个条件同时抓取数据从一个表或多个表. 如果给定的条件满意,意味着true,然后从表中返回特定值.你会使用WHERE子句来筛选记录 ...

  3. smarty 运算符列表

    下面是可用的运算符列表,使用中都会放到元素的中间并且用空格分隔. 注意列表中[方括号]的是可选的,而且还会列出对应PHP的表达式. 详见:Chapter 7. 内置函数 运算符 别名 语法示例 含义 ...

  4. ThinPHP5.0 目录结构

    官网文档  https://www.kancloud.cn/manual/thinkphp5/118008 project 应用部署目录├─application 应用目录(可设置)│ ├─commo ...

  5. Html5怎么导出图片

    其实很简单, 首先需要两个js文件 jquery.min.js html2canvas.js 直接上代码,几行就解决了 <a id="example1" onclick=&q ...

  6. caffe的pad的报错

    CHECK((!conv_param.has_stride() && conv_param.has_stride_h() && conv_param.has_strid ...

  7. hibernate4+spring3+struts2搭建框架实例

    1.所需要的JAR包 2.web.xml配置文件,这个和平时的配置是一样的 <?xml version="1.0" encoding="UTF-8"?&g ...

  8. Web字节码(WebAssembly) Emscripten编译器安装

    首先你需要提前安装 git python 环境并且Ctrl+R输入cmd在windows的dos界面下能够运行 第一步: 在github上downloade下来emsdk git clone http ...

  9. HDU-2544-最短路(Bellman-Ford)

    Bellman-Ford算法是一个时间复杂度很高,但是它可以用来判断负环 负环就是上面的图,那个环的整体值小于零了,所以就是负环. 我们用Bellman-Ford算法进行更新,打一个表出来: k a ...

  10. Python自动化测试框架——数据驱动(从文件中读取)

    学过编程的伙伴们都知道,数据不仅可以从代码中读取,还可以从文件中读取. 今天小编就简要的介绍一下从文件中读取数据,并应用到自动化测试中方法. 先来展示下接下来将要用到的文件在项目中的结构 从txt文件 ...