UVA 10765 Doves and bombs (cut top)

Source: Internet
Author: User



Test instructions: Given a connected undirected graph of n points, the "pigeon value" of a point is defined as the number of connected blocks after it is deleted. "Pigeon value" for each point.

Idea DFS checks to see if each point is a cut-off, and how many connected components are marked after the point is removed

#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream > #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack& Gt  #include <string> #include <map> #include <set> #define EPS 1e-6 #define LL Long long using namespace std; const int MAXN = 10000 + 100;const int INF = 0x3f3f3f3f;int N, m;vector<int> g[maxn];int VAL[MAXN], NODE[MAXN]; Node array record Node ID indirect sort BOOL cmp (int x, int y) {return val[x] = = Val[y]? x < y:val[x] > Val[y];}        int PRE[MAXN], dfs_clock;int dfs (int u, int fa) {//u parent node in the Dfs tree is FA int Lowu = Pre[u] = ++dfs_clock;int Child = 0; Number of child nodes for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];if (!pre[v]) {//not accessed v child++;int lowv = dfs (v, u); low    u = min (Lowu, LOWV); Update the low function of u with the low function of the descendant if (Lowv >= pre[u]) {val[u]++;}}  else if (Pre[v] < Pre[u] && v! = FA) Lowu = min (Lowu, pre[v]); Update U's low function with reverse edge} if (FA < 0 && Child = = 1) val[u] = 1;return Lowu; } void Init () {Dfs_clock = 0;memset (pre, 0, sizeof (PRE)), for (int i = 0; i < n; i++) {g[i].clear (); Node[i] = i;val[i] = 1;} int x, Y;while (scanf ("%d%d", &x, &y) = = 2 && x >= 0) {g[x].push_back (y); G[y].push_back (x);}}  void Solve () {DFS (0,-1), Sort (node, node+n, CMP), for (int i = 0; i < m; i++) cout << node[i] << "<< Val[node[i]] << Endl; cout << Endl;} int main () {//freopen ("Input.txt", "R", stdin), while (scanf ("%d%d", &n, &m) = = 2 && N) {init (); Solve ();} return 0;}

UVA 10765 Doves and bombs (cut top)

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.