UVA-315 Network and UVA-10199 (for cutting top)

Source: Internet
Author: User
Tags cmath

Links:

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20837

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21278

Ask for a bare question on the top of the cut.


UVA-315

#include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include < cstdio> #include <vector> #include <stack> #include <cmath> #include <queue> #include <map > #define Lson o<<1,l,m#define rson o<<1|1,m+1,r#define Mem (a) memset (A,0,sizeof (a)) typedef long Long LL; const int N = 100005;const int M = 105;const ll mod = 1000000009;using namespace std;int n;vector <int> g[n];int Dfs _clock, bcc_cnt, Pre[n], iscut[n], bcc[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];if (pre[v] = = 0) {Child++;int LOWV = dfs (v, u); lowu = min (Lowu, LOWV); if (LOWV >= pre[u]) {Iscut[u] = 1;}} else if (Pre[v] < Pre[u] && v! = FA) {Lowu = min (Lowu, pre[v]);}} if (FA < 0 && child = = 1) {Iscut[u] = 0;} return LOWU;} void Find_bcc () {mem (pre), mem (iscut), mem (bcc);d fs_clock = bcc_cnt = 0;for (int i = 0; i < n; i++) {if (pre[i] = = 0) {DFS (I,-1);}}} int main () {//freopen ("In.txt", "R", stdin), while (Cin >> N, N) {GetChar (); for (int i = 0; i < n; i++) {G[i].clear ( );} String Line;while (Getline (CIN, line)) {if (line = = "0") break;int X;stringstream SS (line); int ok = 1, u;while (SS >> X {x--;//printf ("%d", x+1), if (ok) {u = X;ok = 0;} else {g[u].push_back (x); G[x].push_back (U);}} Puts ("");//for (int i = 0; I < n; i++) {//printf ("%d:", i+1);//for (int j = 0; J < G[i].size (); J + +) {//printf ("%d", G[i][j] + 1);//}//puts ("");//}find_bcc (); int ans = 0;for (int i = 0; I < n; i++) {if (iscut[i]) ans++;} printf ("%d\n", ans);} return 0;}



UVA-10199

#include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include < cstdio> #include <vector> #include <stack> #include <cmath> #include <queue> #include <map > #include <set> #define Lson o<<1,l,m#define Rson o<<1|1,m+1,r#define Mem (a) memset (A,0,sizeof (a) typedef long long ll;const int n = 105;const int M = 10005;const ll mod = 1000000009;using namespace std;int N, m;vector <int> g[n];int Dfs_clock, bcc_cnt, Pre[n], iscut[n], bcc[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];if (pre[v] = = 0) {Child++;int LOWV = dfs (v, u); Lowu = Min (Lowu, LOWV), if (LOWV >= pre[u]) {Iscut[u] = 1;}} else if (Pre[v] < Pre[u] && v! = FA) {Lowu = min (Lowu, pre[v]);}} if (FA < 0 && child = = 1) {Iscut[u] = 0;} return LOWU;} void Find_bcc () {mem (pre), mem (iscut), mem (bcc);d fs_clock = bcc_cnt = 0;for (int i = 0; i < n; i++) {if (pre[i] = = 0) {DFS (I,-1);}}} int main () {//freopen ("In.txt", "R", stdin), int ca = 1;while (cin >> N) {if (n = = 0) break;for (int i = 0; i < n; i+ +) {g[i].clear ();} Map<string, int> mp;string s, T, in[n];for (int i = 0; i < N; i++) {cin >> in[i];mp[in[i]] = i;} CIN >> m;for (int i = 0; i < m; i++) {cin >> s >> t;int x = mp[s];int y = mp[t]; G[x].push_back (y); G[y].push_back (x);} FIND_BCC (); int ans = 0;set<string> st;for (int i = 0; i < n; i++) {if (Iscut[i]) {St.insert (in[i]); ans++;}} if (ca > 1) puts ("");p rintf ("City map #%d:%d camera (s) found\n", ca++, ans); for (set<string>::iterator it = St.beg In (); It! = St.end (); ++it) {cout << *it << Endl;}} return 0;}






UVA-315 Network and UVA-10199 (for cutting top)

Related Article

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.