D-how Many Answers is wrong (HDU 3038)

Source: Internet
Author: User

Finally met a not so boring problem ^ ^
Let's talk about test instructions, there are two people a boy named TT a girl called FF (the name is too casual ....) , this is called TT Boy will often call this girl to play a game, this some is such, casually write a sequence, now TT will select a range, and then let FF calculate the interval of all the number of the and, this is a very very boring game, so FF ready to tease the TT, Sometimes she will deliberately calculate a wrong answer, of course, TT is also more intelligent, he will find that the answer to the previous answer will conflict, then the question came, how many words are false??? //////////////////////////////////////////////////////
Suddenly a look at this problem with and check set seemingly no wool relationship ah, but careful observation can be found that if you want to judge the contradiction is sure to know that there is a conflict with the previous data, because it does not say that the sequence is not a positive integer so there is only one way of conflict, such as first said that even a range 1-10 101-5 26-10 5 with the obvious third sentence can be seen from the problem, the second plus the third with the first is not equal, but they expressed the interval is the same, so the contradiction, but how to judge this contradiction, we can use its endpoint as a point to establish a set, their roots is the left end can reach, If you have the same leftmost end then you can judge if there is a contradiction.


For example, the above figure, we already know the length of AB and the length of the AC, if the following another CB, we can know that the left side of C is a, B, the leftmost is a, then you can determine the length of a AC+CB is equal to the length of AB can be .... If the leftmost side is different, compare the left-most/////////////////////////////////////////////////////////////////#include < Stdio.h>

ConstintMAXN =200005;

intF[MAXN], VAL[MAXN];//Val records the value at the leftmost end of the subscript.

intFind (intX
{
intk = F[x];

if(f[x]! = x)
{
F[X] = Find (f[x]);
VAL[X] + = val[k];
}

returnF[X];
}

intMain ()
{
intN, M;

while(SCANF ("%d%d", &n, &m)! = EOF)
{
intI, U, V, W, ans=0;

for(i=0; i<=n; i++)
{
F[i] = i;
Val[i] =0;
}

while(m--)
{
scanf"%d%d%d", &u, &v, &w);
u = u1;//Notice why you need to lose one

intRU = Find (u), rv = Find (v);

if(ru = = RV && val[u]+w! = Val[v])
ans++;
Elseif(Ru < RV)
{
F[RV] = ru;
VAL[RV] = Val[u]-val[v] + W;
}
Elseif(Ru > RV)
{
F[ru] = RV;
VAL[RU] = Val[v]-val[u]-W;
}
}

printf"%d\n", ans);
}

return0;
}

D-how Many Answers is wrong (HDU 3038)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.