UVA-10765 Doves and bombs (dual unicom Component)

Source: Internet
Author: User
<span id="Label3"></p>Links:<p><p>http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34798</p></p><p><p>To the n-point of the graph and unicom, asked to delete each one point after the number of Unicom components left.</p></p><p><p>To find a cut top if the removal of the cut-off components will increase, or 1 (because The original is a unicom map), delete the number of the cut-off after the block is to see the top of the cut in several double unicom components.</p></p><p><p><br></p></p><p><p></p></p><pre code_snippet_id="674380" snippet_file_name="blog_20150524_1_8147768" class="cpp" name="code">#pragma comment (linker, "/stack:10240000,10240000") #include <algorithm> #include <iostream> #include < sstream> #include <cstring> #include <cstdlib> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #define MoD 4294967296#define MAX 0x3f3f3f3f#define lson o<<1, l, m#define rson o<<1|1, m+1, r#define SZ (x) ((int) ans.size ()) #define MAKE Make_pair#define infl 0x3f3f3f3f3f3f3f3fll#define mem (a) memset (a, 0, sizeof (a)) const double PI = ACOs ( -1. 0); const DOUBLE EPS = 1e-9;const int N = 10005;const int M = 20005;typedef Long Long ll;using namespace Std;int N, m;int p re[n], iscut[n], bcc[n], dfs_clock, bcc_cnt;vector <int> g[n], bcc[n];struct Edge {int u, v;}; Stack <Edge> s;struct C {int id, num;} out[n];int dfs (int u, int fa) {int Lowu = pre[u] = ++dfs_clock; int child = 0; for (int i = 0; i < g[u].size (); I++) {int V = g[u][i]; Edge e = (edge) {u, v}; if (pre[v] = = 0) {s.push (e); child++; int LOWV = DFS (v, u); Lowu = Min (lowu, lowv); If (LOWV >= pre[u]) {iscut[u] = 1; bcc_cnt++; Bcc[bcc_cnt].clear (); For (;;) {Edge x = S.top (); S.pop (); If (bcc[x.u]! = Bcc_cnt) {bcc[bcc_cnt].push_back (x.u); bcc[x.u] = bcc_cnt; } If (bcc[x.v]! = Bcc_cnt) {bcc[bcc_cnt].push_back (x.v); bcc[x.v] = bcc_cnt; } if (x.u = = U && x.v = = V) break; }}}} else if (pre[v] < pre[u] && v! = Fa) {s.push (e); Lowu = Min (lowu, pre[v]); }} if (fa < 0 && Child = = 1) {iscut[u] = 0; } return lowu;}void find_bcc () {mem (pre); Mem (iscut); Mem (bcc); Mem (ans); Dfs_clock = bcc_cnt = 0; for (int i = 0; i < n; i++) {if (pre[i] = = 0) Dfs (i,-1); }}bool cmp (c x, c y) {if (x.num! = y.num) return x.num > y.num; Return X.id < y.id;} int Ans[n];int main () {//freopen ("in.txt", "r", stdin); While (cin >> n >> m && n + m) {int x, y; Mem (ans); for (int i = 0; i < n; i++) {g[i].clear (); } while (scanf ("%d%d", &x, &y) && x! =-1) {g[x].push_back (y); G[y].push_back (x); } FIND_BCC (); for (int i = 1, i <= bcc_cnt; i++) {for (int j = 0; J < bcc[i].size (); J + +) {ans[bcc[i][j ] ] ++; }} int k = 0; for (int i = 0; i < n; i++) {out[i].id = i; If (iscut[i]) {out[i].num = ans[i]; } Else {out[i].num = 1; }} sort (out, out + n, cmp); for (int i = 0; i < m; i++) {printf ("%d%d\n", out[i].id, out[i].num); } puts (""); } return 0;}</pre><br><p><p></p></p><p><p>UVA-10765 Doves and bombs (dual unicom Component)</p></p></span>

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.