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