"cf707b" Bakery (idea title)

Source: Internet
Author: User

Test instructions

There are n cities, m-strips without sides, of which K cities are warehouses

Now choose a bakery in a non-warehouse city, making it a minimum of one warehouse and a minimum for all warehouse distances

(1≤ n, m ≤10^5, 0≤ kn)

Analysis:

The data range determines the solution using only O (n) or O (n log n)

After thinking, you can find that the bakery must be selected in a city directly connected to a warehouse.

Otherwise, it will be through another indirectly connected to the city to go, a few more roads

1 varA,b,c,flag:Array[1..100000] ofLongint;2 N,m,k,i,ans,x:longint;3 4 begin5 readln (n,m,k);6   fori:=1  toM Doreadln (A[i],b[i],c[i]);7   fori:=1  toK Do8  begin9 read (x);Tenflag[x]:=1; One  End; Aans:=Maxlongint; -   fori:=1  toM Do -   ifflag[a[i]]+flag[b[i]]=1  Then the    ifC[i]<ans Thenans:=C[i]; -  ifAns<maxlongint Thenwriteln (ANS) -   ElseWriteln (-1); - End.

"cf707b" Bakery (idea title)

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.