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. 在eclipse中查看你用的tomcat的路径

    在eclipse中查看你用的tomcat的路径   打开eclipse,选择window->Preferences->Server->Runtime Environments选择你的 ...

  2. Servlet和JSP之JSTL学习

    JSTL JSTL就是JSP标准标签库(JavaServer Pages Standard Tag Library, JSTL)是一个定制标签库的集合,用来解决像遍历Map或集合.条件测试.XML处理 ...

  3. Codeforces Round #318 (Div. 2) D Bear and Blocks (数学)

    不难发现在一次操作以后,hi=min(hi-1,hi-1,hi+1),迭代这个式子得到k次操作以后hi=min(hi-j-(k-j),hi-k,hi+j-(k-j)),j = 1,2,3... 当k ...

  4. 安装linux虚拟机(Ubuntu & KALI)

    VMware workstation 15.0.0 ubuntu-18.10-desktop 首先安装VMware 参考资料很多,不再赘述. 之后参考 https://www.cnblogs.com/ ...

  5. 生成随机ID且唯一

    var T = [ {P:11,G:2}, {P:101,G:7}, {P:1009,G:26}, {P:10007,G:59}, {P:100003,G:242}, {P:1000003,G:568 ...

  6. dhtmlTree简单实例以及基本参数设置

    demo实例参考:  <link rel="STYLESHEET" type="text/css" href="css/dhtmlXTree.c ...

  7. CAP 可用性理解

    从容灾角度看可用性. 多机同时返回. 主通过 heart-beat 脑裂. 用 paxos. 性能远距离. 对整体压力较大. 从用户体验的角度看单数据可用性: 不考虑城市灾备的情况发生.只有单机房的 ...

  8. Greenplum/Deepgreen(集群/分布式)安装文档

    Deepgreen分布式安装文档 环境准备 1.安装VMware虚拟机软件,然后在VMware安装三台Linux虚拟机(使用centos7版本) 2.使用的虚拟机如下: 192.168.136.155 ...

  9. MySQL 查询优化之 Index Condition Pushdown

    MySQL 查询优化之 Index Condition Pushdown Index Condition Pushdown限制条件 Index Condition Pushdown工作原理 ICP的开 ...

  10. 网络设备之ospf2

    OSPF(Open Shortest Pass First,开放最短路径优先协议),是一个最常用的内部网管协议,是一个链路状态协议. OSPF的特点 OSPF是一种无类路由协议,支持VLSM可变长子网 ...