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)