Uva315-network (non-direction graph cut point)

Source: Internet
Author: User

Topic links


Test Instructions: The number of cut points is given by a graph without direction .

Ideas: very naked topic, direct template can be.

code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace    std;const int MAXN = 1005;struct edge{int to, next; bool Cut;}    EDGE[MAXN * 10];int HEAD[MAXN], Tot;int LOW[MAXN], dfn[maxn];int Index, Cnt;bool cut[maxn];void addedge (int u, int v) {    Edge[tot].to = v;    Edge[tot].next = Head[u];    Edge[tot].cut = false; Head[u] = tot++;}    void Tarjan (int u, int pre) {int V;    Low[u] = dfn[u] = ++index;    int son = 0;        for (int i = head[u]; I! =-1; i = edge[i].next) {v = edge[i].to;         if (v = = pre) continue; if (!             Dfn[v]) {son++;             Tarjan (V, u);            if (Low[u] > Low[v]) low[u] = Low[v];             if (u! = Pre && low[v] >= Dfn[u]) {Cut[u] = true;    }} else if (Low[u] > Dfn[v]) low[u] = Dfn[v]; } if (U = = Pre && son > 1) cut[u] = true;}    void Init () {memset (head,-1, sizeof (head));memset (DFN, 0, sizeof (DFN));     Memset (cut, false, sizeof (cut));    tot = 0; Index = CNT = 0;}     int main () {int n;         while (scanf ("%d", &n) && N) {init ();        int u, v;            while (scanf ("%d", &u) && u) {char ch;                 while (scanf ("%d%c", &v, &ch)) {Addedge (U, v);                 Addedge (V, u);            if (ch = = ' \ n ') break; }} for (int i = 1; I <= n; i++) if (!        Dfn[i]) Tarjan (i, I);        for (int i = 1; I <= n; i++) if (cut[i]) cnt++;    printf ("%d\n", CNT); } return 0;}


Uva315-network (non-direction graph cut point)

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.