POJ 1236 Network of schools (strong connected components)

Source: Internet
Author: User

POJ 1236 Network of schools Links: http://poj.org/problem?id=1236
Test Instructions:There are some schools connected to a computer network. There is an agreement between these schools: each school maintains a list of schools that publish software to schools in the school list. Note that if school B is in the list of school A, then a is not necessarily in the list of B.
Task A: Calculate how many copies of the software you need at least to prepare each school to receive the software over the network.
Task B: Consider a longer-term task and want to make sure that a new copy of the software is issued to any school, which can be published to every school on the network. In order to achieve this goal, new members must be added to the list. Calculates the minimum number of new members that need to be added.
Ideas:Given a graph, ask a: at least a few points need to be selected in order to access all the pointsThe number of points in the Dag after the indent is 0 is the answer, because these points cannot be accessed through other points.
B: At least how many edges are added so that the original image becomes a strong connected component 1. First, a strongly connected contraction point is formed to form a direction-free graph
2. The statistic degree is 0:outcnt and the degree is 0:incnt
3. If it is already a strong connected component, the answer is 0, otherwise the answer is Max (incnt, outcnt)

/*id: [email protected]prog:lang:c++*/#include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <fstream> #include <cstring> #include <ctype.h> #include <iostream> #include <algorithm> Using namespace std, #define INF (1<<30) #define PI ACOs ( -1.0) #define MEM (A, B) memset (A, B, sizeof (a)) #define REP (I, A, n) for (int i = A; i < n; i++) #define PER (l, a, n) for (int i = n-1; I >= A; i--) #define EPS 1e-6#define debug Puts ("===============") #define PB Push_back#define MKP Make_pair#define All (x) (x). Begin (), (x). End () #define FI first# Define SE second#define SZ (x) ((int) (x). Size ()) #define Posin (x, y) (0 <=) && (x) < n && 0 <= (y ) && (Y) < m) typedef long Long ll;typedef unsigned long long ull;const int maxn = 110;vector<int> G[MAXN] ; int n, M, DFN[MAXN], LOW[MAXN], scc_cnt, Dfs_clock, Sccno[maxn];stack<int> s;void dfs (int u) {low[u] = dfn[u] = ++dfs_clock;    S.push (U);        for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];            if (!dfn[v]) {DFS (v);        Low[u] = min (Low[v], low[u]);    } else if (!sccno[v]) low[u] = min (Low[u], dfn[v]);        } if (low[u] = = Dfn[u]) {scc_cnt++;            while (1) {int x = S.top ();            S.pop ();            SCCNO[X] = scc_cnt;        if (x = = u) break;    }}}void FIND_SCC (int n) {mem (DFN, 0);    Mem (sccno, 0);    scc_cnt = Dfs_clock = 0; for (int i = 1; I <= n; i++) if (!dfn[i]) DFS (i);} int IN[MAXN], out[maxn];int incnt, outcnt;int work () {for (int u = 1; u <= n; u++) {for (int i = 0; i < G[u].size ();            i++) {int U = Sccno[u], V = sccno[g[u][i]];        if (U = V) out[u]++, in[v]++;    }} incnt = outcnt = 0;    cout<<scc_cnt<<endl; for (int i = 1; I <= scc_cnt; i++) {if (!in[i]) Incnt++;    if (!out[i]) outcnt++;    } printf ("%d\n", incnt);    if (scc_cnt = = 1) printf ("0\n"); else printf ("%d\n", Max (incnt, outcnt));}    int main () {scanf ("%d", &n);        for (int i = 1; I <= n; i++) {int x;        while (scanf ("%d", &x), x) {G[I].PB (x);    }} FIND_SCC (n);    Work (); return 0;}


POJ 1236 Network of schools (strong connected components)

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.