51Nod Algorithm Marathon 21 (welcome New Year)

Source: Internet
Author: User

This time the plan of the marathon is in the evening of Friday, play is normal (nonsense, the rest of the question will not = =).

Tell me about the game.

8:00 on time, get the first time to start reading.

A pairing, looks like a binary graph maximum weight matching, a look at the range scare silly, first skip reading the back of the question.

b Complete binary tree variance, probably looked again, good God's appearance, skipped.

C polynomial? Well, I'm sure I won't, jumping and jumping without the FFT and NTT.

d Maximum, hey yo this function what broken thing, can not understand, jump jump jump.

E B June's shooting, crouching tank Byk you have to make a question on the problem is to make such a yard, jumping jump jump.

F Those years, we told the story, the trough this special is a pure language problem, jumping jump.

Hey wait, jump out of the ...

Like a is relatively simple, first think about a forget ...

The first idea is to match the maximum weight of the binary graph, then the cost flow violence, a look at the data range this is obviously not reliable, then began to think about the special nature of the problem.

Inadvertently press a few F5, crouching trough how you do so fast, it seems that I want to complicate, this should be a not too difficult problem.

Think of a matching construction method, greedy seems to be not feasible, other methods for a moment can not think out, it seems to be able to enumerate each side of the calculation contribution ... It feels like it's right, but it's a deep doubt ...

The middle also pressed several times F5, the crouching trough you do the question how so swift ... It seems that the problem is really simple, anyway WA will not be punished, look at my code a bit of enumeration side of the calculation contribution, a hand, ah ha incredibly a ...

I handed it early, so it was the 18th one (why I remember the 19th one ...). Or is it the 19th to submit ...), the rankings are good ... (The other people in the room are a lot of dozens of + only a ...)

Look at the other questions, E-question seems to have seen less connected circle can make the middle of the block also become a hole, feel that they do not write. f the question read for a long time still did not read understand ... d The function of the reading is the decimal bit upside down and then messed up, but still no train of thought. C also looked at the two eyes, a look at other people's running time are more than 10 ms, feel like O (1) The conclusion of the question, hit the print input (this is Python2) but the sample ...

And then began to do B, see the variance of the minimum feel like a three-dimensional average and then the dichotomy of the minimum weight matching, engaged in a half-day to get out of the new tree diameter of the conclusion, but did not introduce the problem of God greedy, wrote a three-point average + minimum cost maximum flow (binary graph min.) (It may also be that the function is not a single peak ...) ...... Tune a half-day tune not come out, mercilessly heart a hand, 1w19t, forget I abandon cure ...

The brain goes up and goes out of therapy. Saturday and Sunday also did not come to do the problem, because the first problem handed early, the final result rank60, really cheap me. (But the rankings are too low, rating down ... =)

Any water competition to get the ranking is a multiple of 20 this buff, saying that luck is really good ...

Today only received a nod of the shield, this speed I give a poor evaluation ...

To put a problem to a question:

Since the distance and maximum of the matching points are required, then the two paths must intersect as far as possible (if disjoint, the end of the interchange two path will not deteriorate). In other words, the matching path must be as long as possible on the side. However, this is not very good, so abandon the construction method, consider the calculation of each side can appear in several matching paths, that is, how much contribution to the answer.

Consider a W-long edge, and the size of the two connected blocks connecting this edge is a and B, respectively. To ensure distance and maximum, we need to make as many matching paths as possible through this edge, so we should try to match the points at both ends of the edge so that this edge is up to min{a,b} times.

The edges and edges don't affect each other (I'm not going to testify ...), so after Dfs/bfs, enumerate each edge to calculate the contribution. In order to insure (explosion proof stack), I use BFS.

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <vector>5 using namespacestd;6 Const intmaxn=100010;7 structedge{intU,v,w;} E[MAXN];8 voidBFS ();9vector<int>G[MAXN];Ten intn,q[maxn],prt[maxn]={0},size[maxn]={0}; One Long Longans=0; A intMain () { -scanf"%d",&n); -      for(intI=1; i<n;i++){ thescanf"%d%d%d",&e[i].u,&e[i].v,&E[I].W); - G[e[i].u].push_back (E[I].V); - G[e[i].v].push_back (e[i].u); -     } + BFS (); -      for(intI=1; i<n;i++){ +         if(prt[e[i].u]==e[i].v) Swap (E[I].U,E[I].V); A         intS=min (size[e[i].v],size[1]-size[e[i].v]); atans+= (Long Long) s*E[I].W; -     } -printf"%lld", ans); -     return 0; - } - voidBFs () { in     intHead=0, tail=0; -q[tail++]=1; to      while(head!=tail) { +         intx=q[head++]; -size[x]=1; the          for(intI=0;i< (int) g[x].size (); i++)if(g[x][i]!=Prt[x]) { *prt[g[x][i]]=x; $q[tail++]=G[x][i];Panax Notoginseng         } -     } the      for(inti=n;i;i--){ +         intx=Q[i]; Asize[prt[x]]+=Size[x]; the     } +}
View Code

Official:

(The construction method is really feasible ...). I still can't understand the greedy structure ... will only write O (n2m2) charge flow ... I'm so embarrassed.)

Reflection:

This time playing the game a little anxious, B also did not have the patience to carefully think/write, play is not very good.

A problem saw others quickly after the problem a bit of panic, a change to stabilize the style, with intuition handed a code, can a estimate is luck. The future of the game or the test must be stable, after all, after all, lost dozens of points on the hundred points but very deadly.

Next stop, Uoj Test Round #2.

Come on.

51Nod Algorithm Marathon 21 (welcome New Year)

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.