Divide the edge weight into two halves and add them to the vertex weights of the two points associated with it.

Source: Internet
Author: User

1005:


If no Edge Weight exists, the point weights are sorted in ascending order ..

Consider the edge and divide the edge right into two halves to add the vertex right of the two points associated with it.

.. Because when two people select different points, this weight will offset each other.

IQ is hard.

 

# Include <iostream> # include <algorithm> # include <string. h> # include <stdio. h> using namespace std; double w [100001]; int main () {// freopen ("1005.in"," r ", stdin); int n, m, I,, c, B; while (~ Scanf ("% d", & n, & m) {memset (w, 0, sizeof (w); for (I = 1; I <= n; I ++) scanf ("% lf", & w [I]); for (I = 1; I <= m; I ++) {scanf ("% d", & a, & B, & c); w [a] ++ = 1.0 * c/2; w [B] ++ = 1.0 * c/2;} double s; s = 0; sort (w + 1, w + n + 1); for (I = n; i> = 1; I-= 2) {s + = w [I]-w [I-1];} printf ("%. 0lf \ n ", s);} return 0 ;}

 

Related Article

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.