Untitled
unknown
c_cpp
25 days ago
1.3 kB
3
Indexable
Never
#include <bits/stdc++.h> using namespace std; int n, m, cnt, tplt; vector<int> vt[1000000]; int a[1000000], low[1000000], b[1000000], c[1000000], d[1000000]; void dfs(int i) { ++cnt; b[i] = cnt; low[i] = b[i]; for(int k = 0; k < vt[i].size(); k++) { int j = vt[i][k]; if(a[j] == -1) { c[i]++; a[j] = i; dfs(j); low[i] = min(low[i], low[j]); } else if(j != a[i]) { low[i] = min(low[i], b[j]); } } } int main() { cin >> n >> m; for(int i = 0; i < m; ++i) { int u, v; cin >> u >> v; vt[u].push_back(v); vt[v].push_back(u); } memset(a, -1, sizeof(a)); for(int i = 1; i <= n; ++i) { if(a[i] == -1) { tplt++; a[i] = 0; dfs(i); } } for(int i = 1; i <= n; ++i) { if(a[i] != 0) { int fi = a[i]; if(low[i] >= b[fi]) ++d[fi]; } } for(int i = 1; i <= n; ++i) { if(a[i] == 0) { cout << tplt + c[i] - 1 << endl; } else { cout << tplt + d[i] << endl; } } return 0; }
Leave a Comment