POJ1236 network of schools

來源:互聯網
上載者:User

標籤:http   int   bsp   網路連接   分享   out   sch   amp   isp   

100個學校,有單向網路連接,從而分享軟體。

問題一:幾個學校得到軟體就可使所有學校都得到?

問題二:再加幾條單向網路可以使得“任意學校得到軟體,就可使得所有學校都有軟體”?

——————————————————————————————————————————————————————————

強連通分量內部可做到“一點得,全部得”,從而可以看做一個點,所以,縮點,得到有向非循環圖。

在圖中,入讀為0的點因為無人與他分享,所以必須直接獲得——問題一答案。

想要“一點得,全部得”,就要全部點成為一個強連通分量,加邊的多少由入讀為0的點數和出度為0的點數的最大值決定。——問題二答案

 

注意:如果所有點本身就是強連通分量,需要特判。

——————————————————————————————————————————————————————————

 

 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #include<stack> 6  7 using namespace std; 8 const int maxn=105; 9 int n;10 struct edge11 {12     int u,v,next;13 }e[10005],ee[10005];14 int head[105],headd[105],js,jss;15 int dfsn[105],low[105],visx;16 stack<int>st;17 bool ins[105];18 int chudu[105],rudu[105];19 int sshu,belong[105];20 void addage(int u,int v,edge e[],int head[],int &js)21 {22     e[++js].u=u;e[js].v=v;23     e[js].next=head[u];head[u]=js;24 }25 void tarjan(int u)26 {27     dfsn[u]=low[u]=++visx;28     st.push(u);29     ins[u]=1;30     for(int i=head[u];i;i=e[i].next)31     {32         int v=e[i].v;33         if(dfsn[v]==0)34         {35             tarjan(v);36             low[u]=min(low[u],low[v]);37         }38         else if(ins[v] && low[u]>dfsn[v])low[u]=dfsn[v];39     }40     if(dfsn[u]==low[u])41     {42         sshu++;43         int tp;44         do45         {46             tp=st.top();47             st.pop();48             ins[tp]=0;49             belong[tp]=sshu;50         }51         while(tp!=u);52     }53 }54 int main()55 {56     scanf("%d",&n);57     for(int v,i=1;i<=n;i++)58     {59         while(scanf("%d",&v)==1 && v!=0)60         {61             addage(i,v,e,head,js);62         }63     }64     for(int i=1;i<=n;i++)65         if(dfsn[i]==0)tarjan(i);66     for(int i=1;i<=js;i++)67     {68         int u=e[i].u,v=e[i].v;69         if(belong[u]!=belong[v])70         {71             addage(belong[u],belong[v],ee,headd,jss);72             chudu[belong[u]]++;rudu[belong[v]]++;73         }74     }75     int chudu0=0,rudu0=0;76     for(int i=1;i<=sshu;i++)77     {78         if(chudu[i]==0)chudu0++;79         if(rudu[i]==0)rudu0++;80     }81     printf("%d\n",rudu0);82     if(sshu==1)printf("0\n");83     else printf("%d\n",max(chudu0,rudu0));84     return 0;85 }
View Code

 

POJ1236 network of schools

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.