POJ 1236 Network of schools

Source: Internet
Author: User

11:

Strong Unicom Component

First: First find out how many points in the graph, even the answer to a, is 0.

Second: First Tarjan, the point with a degree of 0 n a point with a degree of 0 m

We only have this N m connected to the answer for Max (n,m) can be 22 connected

CODE:

#include <cstdio> #include <iostream> #include <vector> #include <stack> #include <algorithm > #include <string.h>using namespace std;const int N =111;vector<int> g[n];int dfn[n],low[n],belong[n], dfs_clock,scc_cnt;stack<int> s;void dfs (int u) {    dfn[u]=low[u]=++dfs_clock;    s.push (U);     for (int i=0;i<g[u].size (); i++)     {        int v=g[u][i];    &NB Sp   if (!dfn[v])         {            DFS (v);      &NBS P     Low[u]=min (Low[u],low[v]);       }        ELSE if (!belong[v]) {&nbs P           low[u]=min (Low[u],dfn[v]);       }     }  &nbs P  if (Low[u]==dfn[u])      {         scc_cnt++;        &NB Sp;while (1)       &NBsp  {             int x=s.top ();             s.pop ();             belong[x]=scc_cnt;            &NBSP;IF (x ==u) break;         }     }}void FIND_SCC (int n) {    dfs_clock=scc_cnt= 0;    memset (belong,0,sizeof (belong));    memset (dfn,0,sizeof (DFN));    for (int i=0;i <n;i++)     if (!dfn[i]) DFS (i);} int main () {    int n,i,j;    scanf ("%d", &n);    for (int i=0;i<n;i++)     {& nbsp       int x;        while (scanf ("%d", &x)!=eof&&x)       &NBS P {            x--;            G[i].push_back (x);    & nbsp  }   }    FIND_SCC (n);    if (scc_cnt==1)   &NBSp {      printf ("1\n0\n");        return 0; }  int in[n], out[n];  memset (in, 0, sizeof in);  memset (out, 0, sizeof off);  for (i=0; i<n; ++i)   for (j=0; J<g[i].size () ; ++J)   {    int v = g[i][j];    if (belong[i]! = Belong[v])     {      out [Belong[i]]++;      in  [belong[v]]++;   } }  int in_tot = 0, Out_tot = 0;&N Bsp for (I=1; i<=scc_cnt; ++i)   {    if (!in[i]) in_tot++;    if (!out[i]) out_tot++; }  printf ("%d\n%d\n", In_tot,max (In_tot,out_tot));  return 0;}

Templates for SCC

POJ 1236 Network of schools

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.