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)