1 / 11

11354: Bond

11354: Bond. ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 1 1354: Bond 解題者: 蔡權昱 解題日期: 200 8 年 12 月 08 日

nola-dennis
Download Presentation

11354: Bond

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 11354: Bond • ★★★☆☆ • 題組:Problem Set Archive with Online Judge • 題號:11354: Bond • 解題者:蔡權昱 • 解題日期:2008年12月08日 • 題意:龐德又來拯救世界了! 他希望從s到t去偷車子來使用,但是每條路上都有警察。由於每條路警察的注意力都不同,所以我們定義由s走到t這條路徑的危險程度ds-t,等於s到t中每一段的危險程度di最大的那一個dmax。題目會給你點和路徑的數目,和很多組s-t,你要回答每組s-t的危險程度ds-t是多少。

  2. 題意範例:Sample input 4 5 // n,m 1 2 10 // 1-2 危險程度為10 1 3 20 1 4 100 2 4 30 3 4 10 2 // 2組問題 1 4 // 1-4的危險程度是多少? 4 1 Sample output 20 20

  3. 解法:Greedy, Union and Find, Latest Common Ancestor • 先把所有的路徑依照危險 disort過(由小到大)O(m*logm) • 接著依序看每一條路徑(edge)所連接的兩個點i,j有沒有在同一個Set,有的話就跳過不用做。O(m*logm) • 沒有的話,就把就把i的root和j的rootUnion起來,且在那條edge上加上weight di 。 • 最後對於每個詢問s,t,只要在Union&Find tree上找到s和t的LCA k,然後答案就是max (dk-s,ds-t)。O(logn)

  4. 解法範例: • 4 5 • 1 2 10 • 1 3 20 • 1 4 100 • 2 4 30 • 3 4 10 • 1 • 1 4 • Ans: 1 – 3 – 4 is 20 1 2 10 20 30 100 3 4 10

  5. 解法範例: • s t di// after sort • 1 2 10 • 3 4 10 • 1 3 20 • 2 4 30 • 1 4 100 0 0 0 0 1 2 3 4

  6. 解法範例: • s t di • 1 2 10 • 3 4 10 • 1 3 20 • 2 4 30 • 1 4 100 0 0 0 2 3 4 10 1

  7. 解法範例: • s t di • 1 2 10 • 3 4 10 • 1 3 20 • 2 4 30 • 1 4 100 0 0 2 4 10 10 1 3

  8. 解法範例: • s t di • 1 2 10 • 3 4 10 • 1 3 20 // 1’s root is 2, 3’s root is 4 • 2 4 30 • 1 4 100 0 4 20 10 2 3 10 1

  9. 解法範例: • s t di • 1 2 10 • 3 4 10 • 1 3 20 • 2 4 30 // same set,skip • 1 4 100 0 4 20 10 2 3 10 1

  10. 解法範例: • s t di • 1 2 10 • 3 4 10 • 1 3 20 • 2 4 30 • 1 4 100 // same set,skip 0 4 20 10 2 3 10 1

  11. 解法範例: • Query:1 4 • 1&3 ‘s LCA is 4 • d4-1 is 20 • d4-3 is 10 • Max is 20 0 4 20 10 2 3 10 1

More Related