P1550 [usaco 08oct] Drilling Hole

Source: Internet
Author: User

P1550 [usaco 08oct] Drilling Hole

The question is simple, but it reminds us of the importance of graph creation.

In many cases, you need to add a secondary vertex instead of creating the given information.

However, this question is true.

# Include <cstdio> # include <algorithm> # include <iostream> # include <cstring> Using STD: sort; const int maxn = 500; struct node {int A, B; int val; bool operator <(const node & A) const {return Val <. val ;}}; node line [maxn * maxn]; int f [maxn], tail; int find (int x) {return f [x] = (F [x] = x? X: Find (F [x]);} int main () {int N; scanf ("% d", & N); For (INT I = 1; I <= N; I ++) f [I] = I; int A; For (INT I = 1; I <= N; I ++) {scanf ("% d", & A); line [++ tail]. a = 0; line [tail]. B = I; line [tail]. val = A ;}for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= N; j ++) {scanf ("% d", & A); line [++ tail]. A = I; line [tail]. B = J; line [tail]. val = A;} Sort (LINE + 1, line + 1 + tail); int get = 0, pass = 1, ANS = 0; while (get <n) {int F1 = line [pass]. a, f2 = line [pass]. b; F1 = Find (F1); F2 = find (F2); If (F1! = F2) {Get ++; F [F1] = F2; ans + = line [pass]. val;} Pass ++;} printf ("% d", ANS );}

p1550 [usaco 08oct] Drilling Hole

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.