How Many Answers Are Wrong

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 626 Accepted Submission(s): 283
 
Problem Description
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)

 
Input
Line 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.

 
Output
            A 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
 
 
Source
2009 Multi-University Training Contest 13 - Host by HIT
 
Recommend
gaojie
/*
A到B的和为W,可以理解为B比A大W,然后将AB加入并查集,如果B有父节点那么,B一定到某区间内的值就已经确定了,
在判断一下正不正确就可以了
*/
#include<bits/stdc++.h>
using namespace std;
int n,m;
int bin[];//用于构建并查集
int val[];//用于保存该节点到父节点的距离
int x,y,v;
int cur=;
int findx(int x)
{
int temp=x;
while(x!=bin[x])
{
val[temp]+=val[bin[x]];//将该节点到附加点的距离加起来
x=bin[x];
//cout<<"x="<<x<<endl;
}
bin[temp]=x;//路径压缩,将所有子孙节点都加到根节点下方
return x;
}
void inti()
{
for(int i=;i<=n;i++)
bin[i]=i,val[i]=;
cur=;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
inti();
//cout<<n<<" "<<m<<endl;
for(int i=;i<m;i++)
{
scanf("%d%d%d",&x,&y,&v);
//cout<<x<<" "<<y<<" "<<v<<endl;
x-=;
int fx=findx(x);
int fy=findx(y);
//cout<<fx<<" "<<fy<<endl;
if(fx!=fy)
{
bin[fy]=fx;
val[fy]=val[x]-val[y]+v;
}
else
{
if(val[y]-val[x]!=v)
cur++;
}
}
printf("%d\n",cur);
}
return ;
}

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. HDU 3038 How Many Answers Are Wrong(带权并查集)

    传送门 Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, ...

  3. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  4. linux下RTNETLINK answers: File exists的解决方案

    重启网卡时 出现 :RTNETLINK answers: File exists  提示 以下是网卡出来错误的解决方法: 第一种: 和 NetworkManager 服务有冲突,这个好解决,直接关闭 ...

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

  6. 101+ Manual and Automation Software Testing Interview Questions and Answers

    101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...

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

  8. UNIX command Questions Answers asked in Interview

    UNIX or Linux operating system has become default Server operating system and for whichever programm ...

  9. RTNETLINK answers: File exists错误

    解决ssh连接虚拟机出错,RTNETLINK answers: File exists 解决步骤如下: 使用ssh连接虚拟机的时候,发现目标主机无法连接,登录虚拟机,查看ssh监听是否开启: 发现监听 ...

  10. hdu 3038 How Many Answers Are Wrong

    http://acm.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 MS ( ...

随机推荐

  1. JS设计模式(一) 单例模式

    命名空间 单例模式是JavaScript中最常见的一种模式,通过这种模式可以为我们提供一个命名空间,例如jQuery库的命名空间为jQuery或$.命名空间的使用是为了让代码更加整洁,在多人协作开发的 ...

  2. 实例讲解webpack的基本使用第四篇

    这一篇来讲解一下webpack的loader的使用,用webpack打包文件,css,img,icon等都需要下载安装对应的loader文件,并且写好配置项,才可以进行打包,废话不多说,直接开始实战. ...

  3. 用css绘制各种图形

    1.用css绘制三角形 http://www.cnblogs.com/blosaa/p/3823695.html

  4. ElasticSearch入门(2) —— 基础概念

    在Elasticsearch中,文档归属于一种类型(type),而这些类型存在于索引(index)中,我们可以画一些简单的对比图来类比传统关系型数据库: Relational DB -> Dat ...

  5. 用 Python 撸一个区块链

    本文翻译自 Daniel van Flymen 的文章 Learn Blockchains by Building One 略有删改.原文地址:https://hackernoon.com/learn ...

  6. Java常用异常整理

    填坑,整理下Java的常用异常.正确使用异常在实际编码中非常重要,但面试中的意义相对较小,因为对异常的理解和应用很难通过几句话或几行代码考查出来,不过我们至少应答出三点:异常类的继承关系.常用异常类. ...

  7. PHP 生成毫秒时间戳

    PHP的time()函数生成当前时间的秒数,但是在一些情况下我们需要获取当前服务器时间和GMT(格林威治时间)1970年1月0时0分0秒的毫秒数,与Java中的currentTimeMilis()函数 ...

  8. vue-chat项目之重构与体验优化

    前言 vue-chat 也就是我的几个月之前写的一个基于vue的实时聊天项目,到目前为止已经快满400star了,注册量也已经超过了1700+,消息量达2000+,由于一直在实习,没有时间对它频繁地更 ...

  9. Milk Patterns poj3261(后缀数组)

    Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9274   Accepted: 4173 Cas ...

  10. 2008-2009 ACM-ICPC, NEERC, Southern Subregional ContestF

    Problem F. Text Editor Input file: stdin Output file: stdout Time limit: 1 second Memory limit: 64 m ...