int dfn[100005], low[100005], tme, q[100005], top; bool gd[100005]; vector<int> e[200005];
voidtarjan(int x){ dfn[x] = low[x] = ++tme; q[++top] = x; int now = 0; for (int i = head[x]; i; i = pre[i]) { int y = to[i]; if (!dfn[y]) { tarjan(y); low[x] = min(low[x], low[y]); if (dfn[x] <= low[y]) { n++; int z = 0; do { z = q[top]; e[n].push_back(z); e[z].push_back(n); top--; } while (z != y); e[n].push_back(x); e[x].push_back(n); } } else { low[x] = min(low[x], dfn[y]); } } }
voiddfs(int x, int fa){ if (x <= nn) siz[x] = 1; for (auto y : e[x]) { if (y == fa) continue; dfs(y, x); if (x <= nn) { ans[x] += 1ll * siz[x] * siz[y]; } siz[x] += siz[y]; } if (x <= nn) { ans[x] += 1ll * siz[x] * (nn - siz[x]); } }
intmain(){ read(n); nn = n; read(m); for (int i = 1; i <= m; i++) { int a, b; read(a); read(b); addedge(a, b); } tarjan(1); dfs(1, 0); for (int i = 1; i <= nn; i++) { printf("%lld\n", ans[i] * 2); //u->v和v->u都要算 } return0; }