Hdu1827 's strong Unicom

Source: Internet
Author: User

Summer HolidayTime limit:10000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1430 Accepted Submission (s): 645


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 to help everyone booked a new Malaysian Thai 7th tour, Wiskey really happy night sleepless ah. He's thinking about it. To tell the news to everyone, although he has all the contact information, but a link in the past is too time-consuming and telephone costs. He knows that other people also have contact information so that he can inform others. Let other people help inform others.

You can help Wiskey figure out how many people to tell at least. How much is it going to take at least a phone bill to get all the people notified?


Input multiple test arrays, ending with EOF.
The first line is two integers N and M (1<=n<=1000, 1<=m<=2000). Represents the number of people and contact logarithm.
The next line has n integers, indicating the phone charges for wiskey contact person I.
Then there are m lines, each line has two integer x, y, which means x can contact Y, but does not mean Y can also contact X.



The output outputs the minimum number of contacts and the minimum cost.
Each case outputs an answer line.

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
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string > #include <queue> #include <algorithm> #include <map> #include <cmath> #include <iomanip > #define INF 99999999typedef long ll;using namespace Std;const int Max=1000+10;int n,m,size,top,index;int Head[ma X],val[max],dfn[max],low[max];int mark[max],stack[max];struct Edge{int V,next; Edge () {}edge (int v,int NEXT): V (v), next (next) {}}edge[max*2];void Init (int num) {for (int i=0;i<=num;++i) Head[i]=-1, mark[i]=0;size=top=index=0;} void Insertedge (int u,int v) {Edge[size]=edge (v,head[u]); head[u]=size++;} void Tarjan (int u) {if (Mark[u]) return;dfn[u]=low[u]=++index;stack[++top]=u;mark[u]=1;for (int i=head[u];i! = -1;i= Edge[i].next) {int V=edge[i].v;tarjan (v), if (mark[v] = = 1) low[u]=min (Low[u],low[v]);} if (dfn[u] = = Low[u]) {while (stack[top]! = u) {mark[stack[top]]=-1;val[u]=min (val[u],val[stack[top]]); low[stack[top-- ]]=low[u];} Mark[u]=-1;--top;}} int main () {int u,v; while (~scanf ("%d%d", &n,&m)) {Init (n); for (int i=1;i<=n;++i) scanf ("%d", val+i); for (int i=0;i<m;++i) { scanf ("%d%d", &u,&v); Insertedge (U,V); }for (int i=1;i<=n;++i) {if (Mark[i]) Continue;tarjan (i);} for (int i=0;i<=n;++i) mark[i]=0;for (int i=1;i<=n;++i) {for (int j=head[i];j! = -1;j=edge[j].next) {v=edge[j].v;if (Low[i] = = Low[v]) continue;mark[low[v]]=1;}} int sum=0,ans=0;for (int i=1;i<=n;++i) {if (!mark[low[i]] && dfn[i] = = Low[i]) ++ans,sum+=val[i];mark[low[i]] = 1;} printf ("%d%d\n", ans,sum);} return 0;}



Hdu1827 's strong Unicom

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.