HDU 3749 Financial Crisis

Source: Internet
Author: User

Financial crisistime limit:2000msmemory limit:32768kbthis problem would be judged onHDU. Original id:3749
64-bit integer IO format: %i64d Java class name: Main Because of the financial crisis, a large number of enterprises go bankrupt. In addition to this, and other enterprises, which has trade relation with the Bankrup enterprises, is also faced with Closin G down. Owing to the market collapse, profit decline and funding chain intense, the Debt-ridden entrepreneurs
The turn to the enterprise with stably developing for help.

Nowadays, there exist a complex net of financial trade relationship between enterprises. So if one of enterprises on the same financial chain are faced with bankrupt, leading to cashflow ' s obstruction, the other Enterprises related with it is influenced as well. At the moment, the foresight entrepreneurs is expected the safer cooperation between enterprises. In this sense, they want to know how many financial chains between some pairs of enterprises is independent with each oth Er. The indepence is defined so if there exist, roads which is made up of enterprises (VERTEXS) and their financial trade Relations (Edge) has the-common start point S and end point T, and expect S and T, none of other enterprise in, and chains is included in these and roads at the same time. So and if one of Enterpirse bankrupt in one's road, the other is not being obstructed.

Now there is N enterprises, and has M pair of financial trade relations between them, the relations is Mutual. They need to ask about Q pairs of enterprises ' safety situations. When both enterprises has a or more independent financial chains, we say they is safe enough, you needn ' t provide exact Answers.InputThe Input consists of multiple test cases. The first line of all test case contains three integers, n (3 <= n <=), M (0 <= M <= 10000) and Q ( 1 <= Q <= 1000). Which is the number of enterprises, the number of the financial trade relations and the number of queries.
The next M lines, each line contains the integers, u, v (0 <= u, v < N && u! = V), which means Enterpirse U and Enterprise V have trade relations, you can assume that the input would not be has parallel edge.
The next Q lines, each line contains the integers, u, v (0 <= u, v < N && U = v), which means Entrepreneu RS would ask you the financial safety of Enterpirse U and Enterprise v.
The last test case was followed by three zeros in a single line, which means the end of the input.OutputFor each case, the output of the test Case number formated as sample output. Then for each query, the output "zero" if there is no independent financial chains between those the enterprises, output "one" If there is only one such chains, or output ".Sample Input
3 1 20 10 21 04 4 20 10 21 22 31 21 30 0 0
Sample Output
Case 1:zeroonecase 2:two or Moreone
SourceHDU 3rd "Vegetable-birds Cup" programming Open Contest Problem Solving: Point two connected components give you an undirected graph, and then there are some questions, ask you from the beginning to the end point, in addition to the beginning and the end point has a point, there are no other points of intersection of the path how many if u V not connected, output 0 if u v belongs to the same point two connected components, then output two or more, you need to pay attention to the special case only the point double connected components, this to output 1 of the remaining output 1
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =5010;4 structArc {5     intu,v;6Arcintx =0,inty =0) {7U =x;8v =y;9     }Ten }; One intlow[maxn],dfn[maxn],bccno[maxn],clk,bcc_cnt; Avector<int>G[MAXN],BCC[MAXN],BELONG[MAXN]; -Stack<arc>Stk; - voidTarjan (intUintFA) { theDfn[u] = Low[u] = + +CLK; -     BOOLFlag =false; -      for(inti = g[u].size ()-1; I >=0; --i) { -         if(!flag && g[u][i] = =FA) { +Flag =true; -             Continue; +         } A         if(!Dfn[g[u][i]]) { at Stk.push (Arc (u,g[u][i)); - Tarjan (g[u][i],u); -Low[u] =min (Low[u],low[g[u][i]]); -             if(Low[g[u][i]] >=Dfn[u]) { -bcc[++bcc_cnt].clear (); -                  while(true) { inArc e =stk.top (); - Stk.pop (); to                     if(BCCNO[E.U]! =bcc_cnt) { +BCCNO[E.U] =bcc_cnt; - Bcc[bcc_cnt].push_back (E.U); the Belong[e.u].push_back (bcc_cnt); *                     } $                     if(BCCNO[E.V]! =bcc_cnt) {Panax NotoginsengBCCNO[E.V] =bcc_cnt; - Bcc[bcc_cnt].push_back (E.V); the Belong[e.v].push_back (bcc_cnt); +                     } A                     if(E.U = = U && e.v = = G[u][i]) Break; the                 } +             } -}Else if(Dfn[g[u][i]) <Dfn[u]) { $ Stk.push (Arc (u,g[u][i)); $Low[u] =min (Low[u],dfn[g[u][i]]); -         } -     } the } - intUF[MAXN];Wuyi intFind (intx) { the     if(x = uf[x]) uf[x] =Find (uf[x]); -     returnUf[x]; Wu } - voidinit () { About      for(inti = CLK = bcc_cnt =0; i < MAXN; ++i) { $Bccno[i] = Dfn[i] =0; - g[i].clear (); - belong[i].clear (); -Uf[i] =i; A     } +      while(!stk.empty ()) Stk.pop (); the } - intMain () { $     intN,m,q,u,v,cs =1; the      while(SCANF ("%d%d%d", &n,&m,&q), n| | m| |q) { the init (); the          for(inti =0; I < m; ++i) { thescanf"%d%d",&u,&v); - G[u].push_back (v); in g[v].push_back (u); theU =Find (u); thev =Find (v); About             if(U = v) uf[v] =u; the         } the          for(inti =0; I < n; ++i) the             if(!dfn[i]) Tarjan (i,-1); +printf"Case %d:\n", cs++); -          while(q--) { thescanf"%d%d",&u,&v);Bayi             if(Find (u)! = Find (v)) puts ("Zero"); the             Else { the                 BOOLFlag =false; -                  for(Auto &A:belong[u]) -                      for(Auto &B:belong[v]) the                         if(A = = B && bcc[a].size () >2) theFlag =true; thePuts (flag?)"Both or more":" One"); the             } -         } the     } the     return 0; the}
View Code

HDU 3749 Financial Crisis

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.