Description
TT and FF are ... friends. Uh ... very very good friends-________-b
FF is a bad boy, he's always wooing TT-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 inclu sively). After that, FF would ask TT what's the sum of the subsequence he chose is. The next, TT'll answer FF ' s question. Then, the 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 @ all. To punish FF, she often tells FF the wrong answers on purpose.
The bad boy isn't a fool man. FF detects some answers is incompatible. Of course, these contradictions make it difficult to calculate the sequence.
However, TT is a nice and lovely girl. She doesn ' t has the heart to is hard on FF. To save time, she guarantees the answers be all right if there is no logical mistakes indeed.
What's more, if FF finds a answer to be wrong, he'll ignore it when judging next answers.
But there'll be, so many questions, the poor FF can ' t make sure whether, the current answer are right or wrong in a moment. So he decides-to-write a program-to-help him with this matter. The program would receive a series of questions from FF together with the answers FF have received from TT. The aim of this program was to find what many answers is wrong. Only by ignoring the wrong answers can FF work out the entire sequence of integers. Poor FF has no time-to-do job. And now he's asking for your help~ (what 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 the sum from Ai to Bi are Si. It ' s guaranteed that 0 < Ai <= Bi <= N.
You can assume this any sum of subsequence are fit in 32-bit integer.
Output
A single line with an integer denotes how many answers is wrong.
Sample Input
10 51 10 1007 10 281 3 324 6 416 6 1 that gives 10 numbers, five sets of test data from 1 to 10 and 100 from 7 to 10 and 28 from 1 to 3 and 32 from 4 to 6 and 41 from 6 to 6 and 1 for the test data.
Sample Output
1 source third Encounter and check set, this time must bear in mind, do not write out, another: each time to provide the data is in a set
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace std;const int Maxn=200010;int f[maxn];int val[maxn];int Find (int x) { if (f[x]==-1) return x; int Tmp=find (f[x]); VAL[X]+=VAL[F[X]]; return f[x]=tmp;} int main () { int n,m; int u,v,w; while (scanf ("%d%d", &n,&m) ==2) { memset (f,-1,sizeof (F)); Memset (Val,0,sizeof (Val)); int ans=0; while (m--) { scanf ("%d%d%d", &u,&v,&w); u=u-1; int t1=find (u); int T2=find (v); if (t1!=t2) { f[t2]=t1; val[t2]=val[u]-val[v]+w; } else { if (val[v]-val[u]!=w) ans++; } } printf ("%d\n", ans); } return 0;}
How many Answers is wrong