#1183: Connectivity One • Cutting edge and cutting point time limit:10000msSingle Point time limit:1000msMemory Limit:256MBDescribe
Remember the last time little Hi and Little Ho School was hacked, the attack finally caused the school network data loss. To avoid the recurrence of such a situation, the school decided to redesign the campus network.
The school now altogether possesses n servers (number 1. N) and M-bar connections, ensure that any two servers can be connected directly or indirectly through the data communication.
When a hacker attacks, the school will immediately cut off a connection in the network or immediately shut down a server, so that the entire network is isolated into two separate parts.
For example, for the following networks:
At least one path is connected between every two points, and when you cut off the edge (3,4), you can see that the entire network is quarantined as {1,2,3},{4,5,6} two parts:
If server 3 is shut down, the entire network is quarantined as {1,2},{4,5,6} two parts:
Little Hi and Little ho want to know what connections and which points are closed in the school's network, allowing the entire network to be quarantined into two parts.
In the example above, there is an edge (3,4) that satisfies the condition, point 3 and point 4.
Tip: Cutting edges & cutting points
Input
Line 1th: 2 positive integers, n,m. Represents the number of points N, the number of edges M. 1≤n≤20,000, 1≤m≤100,000
2nd.. M+1 line: 2 positive integers, u,v. Indicates that there is an edge (u,v) and that the U,v two servers are connected. 1≤u<v≤n
Ensure that there is at least one connecting path between the inputs.
Output
Line 1th: Several integers, separated by spaces, indicating the server number that satisfies the requirement. Arranged from small to large. If there are no points to satisfy the requirement, the line outputs null
2nd.. K-line: 2 integers per line, (U,V) represents the edge that satisfies the requirement, u<v. All edges are sorted according to the size of U, u small row in front, when u phase, v small row in front. If no edge is satisfied, no output is required
-
Sample input
-
6 71 21 32 33 44 54 65 6
-
Sample output
-
3 43 4
Title Link: Hicocoder 1183
Verify that your previous code is correct, but this problem is very pit dad, if not cut point, to output Null, WA half a day to find out the problem they have output this sentence ... Plus go over, blame their eyes are not good
Line 1th: Several integers, separated by spaces, indicating the server number that satisfies the requirement. Arranged from small to large. If there are no points to satisfy the requirement, the line outputs null
Cut point judgment:
1, the current point is the starting point for you to start Tarjan (that is, you enter the first point of a DFS search tree) and its son has two, the former more than one parameter can be resolved, the latter with a son variable records the node's search subtree has several.
2, the current point is not the starting point, but the low value of the son node is greater than the dfn[u] value of the current point, that is, the son side can not return is $low[v]>=dfn[u]$.
Cutting edge Judging conditions:
Relatively simple only need to $low[v]>dfn[u]$, and cut the same can not be returned, but because it is for the edge, it must not add equal number, the code added to the re-edge judgment, the title is not clear, but certainly write a little better
Code (Sublime code formatting is really good):
#include <stdio.h> #include <bits/stdc++.h>using namespace std; #define INF 0x3f3f3f3f#define LC (x) (x< <1) #define RC (x) ((x<<1) +1) #define MID (x, y) ((x+y) >>1) #define CLR (Arr,val) memset (arr,val,sizeof (arr) ) #define FAST_IO Ios::sync_with_stdio (false); Cin.tie (0); typedef pair<int, int> pii;typedef Long Long ll;const Double PI = ACOs ( -1.0); const int N = 20010;const int M = 100010;struct edge{int to, NXT, id;}; Edge e[m << 1];int head[n], Tot;int low[n], dfn[n], St[n], top, Ts;bool ins[n], cut[n];vector<pii>bridge;void Init () {CLR (head,-1); tot = 0; CLR (Low, 0); CLR (DFN, 0); top = ts = 0; CLR (ins, false); Bridge.clear (); CLR (cut, false);} inline void Add (int s, int t, int id) {e[tot].to = t; E[tot].id = ID; E[TOT].NXT = Head[s];head[s] = tot++;} void Tarjan (int u, int id, const int &rt) {Low[u] = Dfn[u] = ++ts;st[top++] = U;ins[u] = 1;int V, i;int son = 0;for (i = Head[u]; ~i; i = e[i].nxt) {v = e[i].to;if (e[i].id = = ID) continue;if (!dfn[v]) {++son; Tarjan (v, E[i].id, RT), Low[u] = min (Low[u], low[v]), if (Low[v] > Dfn[u]) bridge.push_back (PII (min (U, v), max (U, v))); if (U = = RT && son > 1) cut[u] = 1;else if (u! = RT && Low[v] >= dfn[u]) cut[u] = 1;} else if (Ins[v]) low[u] = min (Low[u], dfn[v]);} if (low[u] = = Dfn[u]) {do{v = st[--top];ins[v] = 0;} while (U! = v);}} int main (void) {int n, m, A, B, I;while (~SCANF ("%d%d", &n, &m)) {init (); for (i = 0; i < m; ++i) {scanf ("%d%d", &A Mp;a, &b); Add (A, B, i); Add (b, a, i);} for (i = 1; I <= n; ++i) if (!dfn[i]) Tarjan (i,-1, i), int first = 0;for (i = 1; I <= n; ++i) if (Cut[i]) printf ("%s%d", ++first = = 1? "" ":" ", I), if (!first) printf (" Null ");p Utchar (' \ n '); int sz = Bridge.size (); Sort (Bridge.begin (), Bridge.end ()); for (i = 0; I < sz; ++i) printf ("%d%d\n", Bridge[i].first, Bridge[i].second);} return 0;}
Hihocoder 1183 Connectivity One • Cutting edges and cutting points (Tarjan for cutting points and cutting edges)