Mining your own businesstime limit: 6000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1392 accepted submission (s): 219
Problem descriptionjohn digger is the owner of a large using dium phosdex mine. the mine is made up of a series of tunnels that meet at varous large junctions. unlike some owners, Digger actually cares about the welfare of his workers and has a concern about the layout of the mine. specifically, he worries that there may a junction which, in case of collapse, will cut off workers in one section of the mine from other workers (phosdex, as you know, is highly unstable ). to counter this, he wants to install special escape shafts from the junctions to the surface. he cocould install one escape shaft at each junction, but Digger doesn' t care about his workers that much. instead, he wants to install the minimum number of escape shafts so that if any of the junctions collapses, all the workers who keep ve the junction collapse will have a path to the surface.
Write a program to calculate the minimum number of escape shafts and the total number of ways in which this minimum number of escape shafts can be installed.
Inputthe input consists of several test cases. the first line of each case contains a positive integer n (n <= 5 × 10 ^ 4) indicating the number of mine tunnels. following this are n lines each containing two distinct integers S and T, where S and T are junction numbers. junctions are numbered consecutively starting at 1. each pair of junctions is joined by at most a single tunnel. each set of mine tunnels forms one connected unit (that is, you can get from any one junction to any other ).
The last test case is followed by a line containing a single zero.
Outputfor each test case, display its case number followed by the minimum number of escape shafts needed for the system of mine tunnels and the total number of ways these escape shafts can be installed. you may assume that the result fits in a signed 64-bit integer.
Follow the format of the sample output.
Sample Input
91 34 13 51 22 61 56 31 63 261 21 32 42 53 63 70
Sample output
Case 1: 2 4Case 2: 4 1
Source2011worldfinal
Question: I will give you a picture. I will black some of the above points so that after I remove one of them, each point can reach a Black Point and find the minimum number of points and the number of solutions.
Idea: if only one vertex is a cut point in a vertex's dual-connected component, the component must be hacked at a non-cut point. The problem becomes the dual-connected component of the solution point. In a special case, if the full graph is a component, you need to apply two vertices at will.
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <vector> # include <algorithm> # define maxn 100005 # define maxn 100005 # define INF 0x3f3f3f3f # pragma comment (linker, "/Stack: 102400000,102400000") typedef long ll; using namespace STD; int n, m, CNT, TOT, flag; int lev, bcccnt; int head [maxn]; int dfn [maxn], low [maxn]; bool vis [maxn], OK [maxn]; struct node {int V, W, next;} edge [maxn]; int STAU [maxn], sta V [maxn], top, bccno [maxn]; vector <int> BCC [maxn]; void addedge (int u, int V, int W) {CNT ++; edge [CNT]. V = V; edge [CNT]. W = W; edge [CNT]. next = head [u]; head [u] = CNT;} void Tarjan (int u, int pre) {int I, j, T, V, num = 0; low [u] = dfn [u] = ++ lev_for (I = head [u]; I; I = edge [I]. next) {v = edge [I]. v; If (vis [v]) {If (V! = Pre) low [u] = min (low [u], dfn [v]); // The bridge cannot be updated by the father.} else {vis [v] = 1; top ++; STAU [Top] = u; stav [Top] = V; num ++; Tarjan (v, U); If (dfn [u] <= low [v]) {If (pre! = 0) OK [u] = 1; // not root bcccnt ++; BCC [bcccnt]. Clear (); While (! (STAU [Top] = u & stav [Top] = V) {If (bccno [stav [Top]! = Bcccnt) bccno [stav [Top] = bcccnt, bcc [bcccnt]. push_back (stav [Top]); If (bccno [STAU [Top]! = Bcccnt) bccno [STAU [Top] = bcccnt, bcc [bcccnt]. push_back (STAU [Top]); top --;} If (bccno [stav [Top]! = Bcccnt) bccno [stav [Top] = bcccnt, bcc [bcccnt]. push_back (stav [Top]); If (bccno [STAU [Top]! = Bcccnt) bccno [STAU [Top] = bcccnt, bcc [bcccnt]. push_back (STAU [Top]); top --;} low [u] = min (low [u], low [v]);} if (pre = 0 & num> 1) OK [u] = 1;} int main () {int I, j, T, U, V, W, CA = 0; while (scanf ("% d", & M), m) {CNT = n = 0; memset (Head, 0, sizeof (head )); for (I = 1; I <= m; I ++) // graph creation {scanf ("% d", & U, & V); addedge (u, v, 0); addedge (v, U, 0); n = max (n, U); n = max (n, V);} memset (VIS, 0, sizeof (VIS); memset (OK, 0, sizeof (OK); memset (bccno, 0, sizeof (bccno); bcccnt = 0; for (I = 1; I <= N; I ++) // solves the cut point or bridge {If (vis [I]) continue; lev_= 0; vis [I] = 1; top = 0; Tarjan (I, 0);} ll ans = 0, Res = 1; for (I = 1; I <= bcccnt; I ++) {int num = 0; For (j = 0; j <BCC [I]. size (); j ++) {If (OK [BCC [I] [J]) num ++;} If (num = 1) {ans ++; res * = (bcc [I]. size ()-1) ;}}if (bcccnt = 1) {ans = 2; Res = LL (n) * LL (n-1)/2 ;} printf ("case % d: % i64d % i64d \ n", ++ ca, ANS, Res);} return 0 ;}
HDU 3844 mining Your Own Business (point dual-Connected Component)