POJ 1236 Network of schools (strong connectivity tarjan+ indent)

Source: Internet
Author: User

POJ 1236 Network of schools (strong connectivity tarjan+ indent)

ACM

Title Address: POJ 1236

Test Instructions :
Given a graph, ask for a minimum number of points to traverse the full map, and at least to join? Several edges make the graph a strong connected graph.

Analysis :
With Hdu 2767 proving equivalences (the problem) the same topic, just a lot of problems, in fact, converted into a DAG is not difficult to consider, in fact, only to choose the point of 0 points can be.

Code :

/** author:illuz <iilluzen[at]gmail.com>* file:1236.cpp* Create date:2014-07-30 15:13:12* Descrip Ton:tarjan */#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #include <vector> #include <stack> #define REPF (I,A,B) for (int i= (a); i<= (b); i++) typedef long LONG ll;const int N = 105;vector<int> g[n];stack<int> s;int low[n], dfn[n], sccno[n], Tclock, SCC Cnt;int Id[n], od[n];int N, rd;void tarjan (int u) {low[u] = dfn[u] = ++tclock;  S.push (u); int sz = G[u].size (); Repf (i, 0, sz-1) {int v = g[u][i];if (!dfn[v]) {Tarjan (v); Low[u] = min (Low[u], low[v]);} else if (!sccno[v]) {Low[u] = min (Low[u], dfn[v]);}} if (low[u] = = Dfn[u]) {Scccnt++;int v = -1;while (v! = u) {v = s.top (); S.pop (); sccno[v] = scccnt;}}} void Read () {REPF (i, 1, n) {g[i].clear (); while (scanf ("%d", &rd) && Rd) {g[i].push_back (rd);}}} void Find_scc () {tclock = scccnt = 0;memset (DFN, 0, sizeof (DFN)); MEMSET (low, 0, sizeof (low)), memset (sccno, 0, sizeof (SCCNO)), REPF (i, 1, n) {if (!dfn[i]) {Tarjan (i);}}} void Solve () {if (scccnt = = 1) {printf ("1\n0\n"); return;} memset (ID, 0, sizeof (ID)), memset (OD, 0, sizeof (OD)), REPF (U, 1, n) {int sz = g[u].size (), REPF (i, 0, sz-1) {int v = g[u] [I];if (sccno[u]! = Sccno[v]) {id[sccno[v]]++;od[sccno[u]]++;}}} int idnum = 0, Odnum = 0;REPF (i, 1, scccnt) {idnum + = (id[i] = = 0); Odnum + = (od[i] = = 0);} printf ("%d\n%d\n", Idnum, Max (Idnum, Odnum));} int main () {while (~SCANF ("%d", &n)) {read (); FIND_SCC (); Solve ();} return 0;}


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.