1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <bits/stdc++.h>
namespace IO {
inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin) : 0; return s == t ? -1 : *s++; }
template <typename T> inline bool read(T &x) { static char c; static bool iosig; for (c = read(), iosig = false; !isdigit(c); c = read()) { if (c == -1) return false; c == '-' ? iosig = true : 0; } for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0'); iosig ? x = -x : 0; return true; }
inline void read(char &c) { while (c = read(), isspace(c) && c != -1) ; }
inline int read(char *buf) { register int s = 0; register char c; while (c = read(), isspace(c) && c != -1) ; if (c == -1) { *buf = 0; return -1; } do buf[s++] = c; while (c = read(), !isspace(c) && c != -1); buf[s] = 0; return s; }
const int OUT_LEN = 1000000;
char obuf[OUT_LEN], *oh = obuf;
inline void print(char c) { oh == obuf + OUT_LEN ? (fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf) : 0; *oh++ = c; }
template <typename T> inline void print(T x) { static int buf[30], cnt; if (x == 0) { print('0'); } else { x < 0 ? (print('-'), x = -x) : 0; for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 | 48; while (cnt) print((char)buf[cnt--]); } }
inline void print(const char *s) { for (; *s; s++) print(*s); }
inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }
struct InputOutputStream { template <typename T> inline InputOutputStream &operator>>(T &x) { read(x); return *this; }
template <typename T> inline InputOutputStream &operator<<(const T &x) { print(x); return *this; }
~InputOutputStream() { flush(); } } io; }
namespace {
const int MAXN = 100010;
std::vector<int> edge[MAXN + 1];
inline void addEdge(const int u, const int v) { edge[u].push_back(v), edge[v].push_back(u); }
typedef std::vector<int>::iterator Iterator;
int low[MAXN + 1], dfn[MAXN + 1], scc[MAXN + 1], cnt, deg[MAXN + 1], idx;
std::vector<int> st;
inline void tarjan(int u, int fa) { dfn[u] = low[u] = ++idx, st.push_back(u); register bool flag = 0; register int v; for (register int i = 0; i < edge[u].size(); i++) { if ((v = edge[u][i]) == fa && !flag) { flag = 1; continue; } if (!dfn[v]) tarjan(v, u), low[u] = std::min(low[u], low[v]); else low[u] = std::min(low[u], dfn[v]); } if (low[u] == dfn[u]) { cnt++; register int v; do v = st.back(), scc[v] = cnt, st.pop_back(); while (!st.empty() && v != u); } }
using IO::io;
inline void solve() { register int n, m; io >> n >> m; for (register int i = 1, u, v; i <= m; i++) io >> u >> v, addEdge(u, v); tarjan(1, 1); for (register int i = 1; i <= n; i++) for (register Iterator p = edge[i].begin(); p != edge[i].end(); p++) if (scc[i] != scc[*p]) deg[scc[i]]++, deg[scc[*p]]++; register int ans = 0; for (register int i = 1; i <= cnt; i++) if (deg[i] == 2) ans++; io << (ans + 1) / 2; } }
int main() { solve(); return 0; }
|