0 after the explosion, plus a strong unicom component Hdu 4635

Source: Internet
Author: User

Today again zero, and again, how again, burst 0 explode more, and also often hang on the mouth, see this sentence, you must very want to say "", the weak dish is scolded silly, also very normal.

If you are not happy, you may consider looking down.

Turn to E (HDU 4635 strongly connected) question, such a short topic, must first look. Then D (Lightoj 1229), then C (ZOJ 2243), then F (HDU 4711), then B (Codeforces 385D), and then look at a (HDU 3889) Well, I admit, a question looked at a glance will not look, b A look is a line of what a bit of geometric taste on the decisive give up, and then C, silly understanding of the wrong test instructions, submitted has been WA, and then no way to see the E-question, as long as the last to ensure that at least two connected components, you can meet the test instructions, and then the maximum value, it is guaranteed to have and only two For a connected component there can be at most x (x-1) edges, x represents the number of vertices, then an equation, the number of edges F = n*n-n-1+x*x-(n+1) x, and when x is greater (n+1)/2 The greater the difference, the greater the F, in other words, the smallest number of connected component vertices independently, It is possible to combine the other connected components into a single connected component.

But I didn't think of the following.

At this time if the 3 independent, 5, 9, 7 into a connected component, then 3 will be merged with 5,9,7 into a connected component, so can not choose 3,

The smallest can not be selected, then choose 5, the 3, 7, 9 combined, yes.

That is to say, the number of vertices as small as possible and the degree of perceive or zero (a connected component as a point) of the connected components independent.

View Code#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include < algorithm> #include <cmath> #include <vector> #include <map> #include <stack>using namespace Stdtypedef Long LongllConst intINF = 0x3f3f3f3f;Const intN = 100010;int_, Cas=1, N, M;intIn[n], Out[n], num[n];vector<int> G[n];intPre[n], Lowlink[n], Dfs_clock, scc_cnt, sccno[n];stack<int>S;voidDfsintu) {pre[u] = lowlink[u] = ++dfs_clock; S.push (U);intSiz = G[u].size (); for(inti=0; i<siz; i++) {intv = g[u][i];if(!pre[v])            {DFS (v);        Lowlink[u] = min (Lowlink[u], lowlink[v]); }Else if(!sccno[v])        {Lowlink[u] = min (Lowlink[u], pre[v]); }    }if(Lowlink[u] = = Pre[u]) {scc_cnt++; for(;;) {intx = S.top ();            S.pop ();            SCCNO[X] = scc_cnt; num[scc_cnt]++;if(X==u) Break; }    }}voidFIND_SCC () {dfs_clock = 0;    scc_cnt = 0; memset (sccno, 0,sizeof(SCCNO)); memset (pre, 0,sizeof(pre)); for(intI=1; i<=n; i++) {if(!pre[i]) DFS (i); }}voidSolve () {scanf("%d%d", &n, &m); memset (num, 0,sizeof(num)); memset (in, 0,sizeof(in)); memset (out, 0,sizeof(out)); for(intI=1; i<=n; i++) g[i].clear ();intU, v; for(inti=0; i<m; i++) {scanf("%d%d", &u, &v);    G[u].push_back (v); } FIND_SCC ();printf("Case %d:", cas++);if(scc_cnt==1) {printf("-1\n");return; } ll ans = 0, Min = INF; for(intI=1; i<=n; i++) {intSiz = G[i].size (); for(intj=0; j<siz; J + +) {if(Sccno[i]!=sccno[g[i][j]])                {in[sccno[g[i][j]]]++;            out[sccno[i]]++; }        }    } for(intI=1; i<=scc_cnt; i++) {if((in[i]==0 | | out[i]==0) && min>num[i]) Min = Num[i];//printf ("num[%d] =%d\n", I, Num[i]);//printf ("Out =%d, in =%d\n", Out[i], in[i]);} ans = (Min-1) *min-m + (n-min) * (n-min-1) +min* (n-min); Cout<<ans<<endl;}intMain () {//Freopen ("in", "R", stdin);cin>>_; while(_--) solve ();return0;}

The red part is the thinking loophole.

。 Almost, but ACM is not nearly, only AC or no AC.

Let's summarize the topic below
Problem A
HDU 3889 (water problem, won't do)

problem B
Codeforces 385D (DP, test instructions not yet clear)

Problem C
ZOJ 2243 (What treap, the pit)

problem D
Lightoj 1229 (game, not)

problem E
HDU 4635 (...). , 10,000 words omitted here)

Problem F
HDU 4711:

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.