HDU 1827 summer holiday (Tarjan contraction point)

Source: Internet
Author: User
Problem descriptionto see a world in a grain of sand
And a heaven in a wild flower,
Hold infinity in the palm of your hand
And eternity in an hour.
-- William Blake

I heard that lcy helped you book a 7-day tour of the new Mattel. wiskey was so happy that he could not stay at night. He wanted to tell you the news quickly, even though he had contact information for everyone, however, one contact once took too much time and telephone fees. He knows that others also have some contact information, so that he can notify others and ask others for help. Can you help wiskey calculate the minimum number of people to be notified, and the minimum number of phone bills to be paid can be notified to everyone?
 
Input Multiple groups of test arrays, ending with EOF.
The first line has two integers, N and M (1 <= n <= 1000, 1 <= m <= 2000), indicating the number of people and the contact logarithm.
There are n integers in the next line, indicating the phone charge for the person who contacted me by wiskey.
Then there are m rows. Each row has two integers x and y, indicating that X can be associated with y, but not y.
 
Output outputs the minimum number of contacts and the minimum cost.
Each case outputs a line of answers.
 
Sample Input
12 162 2 2 2 2 2 2 2 2 2 2 2 1 33 22 13 42 43 55 44 66 47 47 127 88 78 910 911 10
 
Sample output
3 6. Question: Chinese
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <limits. h> typedef long ll; using namespace STD; const int INF = 0x3f3f3f; # define repf (I, a, B) for (INT I = A; I <= B; ++ I) # define rep (I, n) for (INT I = 0; I <n; ++ I) # define clear (A, x) memset (, x, sizeof A) const int maxn = 1100; const int maxm = 10000; struct node {int U, V; int next;} e [maxm]; int he AD [maxn], cnte; int dfn [maxn], low [maxn]; int s [maxm], top, index, CNT; int belong [maxn], instack [maxn]; int in [maxn], Val [maxn]; int TT [maxn]; // TT stores the minimum values of int n, m; void Init () {Top = cnte = 0; Index = CNT = 0; clear (dfn, 0); clear (Head,-1); clear (instack, 0 );} void addedge (int u, int v) {e [cnte]. U = u; E [cnte]. V = V; E [cnte]. next = head [u]; head [u] = cnte ++;} void Tarjan (int u) {dfn [u] = low [u] = ++ index; instack [u] = 1; s [top ++] = u; f Or (INT I = head [u]; I! =-1; I = E [I]. Next) {int v = E [I]. V; If (! Dfn [v]) {Tarjan (V); low [u] = min (low [u], low [v]);} else if (instack [v]) low [u] = min (low [u], dfn [v]);} int V; If (dfn [u] = low [u]) {CNT ++; do {v = s [-- top]; belong [v] = CNT; instack [v] = 0;} while (u! = V) ;}} void work () {repf (I, 1, n) if (! Dfn [I]) Tarjan (I); clear (in, 0); clear (TT, INF); repf (I, 1, n) {If (TT [belong [I]> Val [I]) TT [belong [I] = Val [I];} repf (k, 1, n) {for (INT I = head [k]; I! =-1; I = E [I]. Next) {int v = E [I]. V; If (belong [k]! = Belong [v]) in [belong [v] ++ ;}} int ans = 0; int num = 0; repf (I, 1, CNT) {If (! In [I]) {num ++; ans + = TT [I] ;}} printf ("% d \ n", num, ANS );} int main () {int U, V; while (~ Scanf ("% d", & N, & M) {Init (); For (INT I = 1; I <= N; I ++) scanf ("% d", & Val [I]); For (INT I = 0; I <m; I ++) {scanf ("% d ", & U, & V); addedge (u, v);} Work ();} return 0 ;}


HDU 1827 summer holiday (Tarjan contraction point)

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.