codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

437C.md (2266B)


      1 Source: https://codeforces.com/problemset/problem/437/C
      2 
      3 C. The Child and Toy
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
     22 
     23 The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1 + *v**f*2 + ... + *v**f**k* energy for removing part *i* where *f*1, *f*2, ..., *f**k* are the parts that are directly connected to the *i*-th and haven't been removed.
     24 
     25 Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts.
     26 
     27 Input
     28 
     29 The first line contains two integers *n* and *m* (1 ≤ *n* ≤ 1000; 0 ≤ *m* ≤ 2000). The second line contains *n* integers: *v*1, *v*2, ..., *v**n* (0 ≤ *v**i* ≤ 105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1 ≤ *x**i*, *y**i* ≤ *n*; *x**i* ≠ *y**i*).
     30 
     31 Consider all the parts are numbered from 1 to *n*.
     32 
     33 Output
     34 
     35 Output the minimum total energy the child should spend to remove all *n* parts of the toy.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4 3  
     43 10 20 30 40  
     44 1 4  
     45 1 2  
     46 2 3
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 40
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 4 4  
     59 100 100 100 100  
     60 1 2  
     61 2 3  
     62 2 4  
     63 3 4
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 400
     70 ```
     71 
     72 Input
     73 
     74 ```
     75 7 10  
     76 40 10 20 10 20 80 40  
     77 1 5  
     78 4 7  
     79 4 5  
     80 5 2  
     81 5 7  
     82 6 4  
     83 1 6  
     84 1 3  
     85 4 3  
     86 1 4
     87 ```
     88 
     89 Output
     90 
     91 ```
     92 160
     93 ```
     94 
     95 Note
     96 
     97 One of the optimal sequence of actions in the first sample is:
     98 
     99 * First, remove part 3, cost of the action is 20.
    100 * Then, remove part 2, cost of the action is 10.
    101 * Next, remove part 4, cost of the action is 10.
    102 * At last, remove part 1, cost of the action is 0.
    103 
    104 So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
    105 
    106 In the second sample, the child will spend 400 no matter in what order he will remove the parts.