POJ 3352-side Double Unicom

Source: Internet
Author: User

Click to open link

Test instructions: The topic is very long does not say, is to seek to add a few sides, arbitrarily delete an edge, the figure or Unicom

Idea: the definition of the side double Unicom component is to delete a side after the diagram is still connected, here is recommended this article is written in detail here, and this is the recommendation of the article in the construction of double-link diagram of the bridge method, then we directly quoted, proof to see that article, for a unicom map, we find all the bridge, the method of bridge is to find the low and DFS array complete, my code is the L and e arrays, the bridge after the deletion of the diagram is definitely a plurality of unicom blocks, and each block is definitely a double-link sub-map, which is defined by the bridge can be seen, and then each piece is shrunk to a point, connected to find a degree of 1 points of the number +1 and 2 is the result, The recommended article has proof

#include <vector> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < Iostream> #include <algorithm>using namespace std;typedef long long ll;const int Inf=0x3f3f3f3f;const int maxn= 1050;vector<int>g[maxn];int l[maxn],cnt[maxn],vis[maxn];int n,m,k;void dfs (int x,int fa) {vis[x]=1;    l[x]=k++;        for (unsigned int i=0;i<g[x].size (); i++) {int t=g[x][i];        if (T==FA) continue;        if (!vis[t]) DFS (T,X);    L[x]=min (L[x],l[t]);    }}int Tarjan () {K=0;dfs ();            for (int i=1;i<=n;i++) {for (unsigned int j=0;j<g[i].size (); j + +) {int t=g[i][j];            if (L[i]!=l[t]) {cnt[l[i]]++;    }}} int ans=0;    for (int i=1;i<=n;i++) {if (cnt[i]==1) ans++; } return (ans+1)/2;}    int V[maxn][maxn];int Main () {int a A, B;        while (scanf ("%d%d", &n,&m)!=-1) {for (int i=0;i<maxn;i++) {g[i].clear (); cnt[i]=0; } memset (viS,0,sizeof (VIS));            for (int i=0;i<m;i++) {scanf ("%d%d", &a,&b);            G[a].push_back (b);        G[b].push_back (a);        } int Ans=tarjan ();    printf ("%d\n", ans); } return 0;}

POJ 3352-side Double 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.