Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nguyen Huu Hoang Minh
- #include <bits/stdc++.h>
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define reset(x) memset(x, 0,sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define N 100005
- #define remain(x) if (x > MOD) x -= MOD
- #define ii pair<int, int>
- #define iiii pair< ii , ii >
- #define viiii vector< iiii >
- #define vi vector<int>
- #define vii vector< ii >
- #define bit(x, i) (((x) >> (i)) & 1)
- #define Task "blo"
- #define int long long
- using namespace std;
- typedef long double ld;
- const int inf = 1e10;
- const int minf = -1e10;
- int n, m;
- vector<int> a[N];
- int num[N], low[N], cnt, par[N];
- int child[N];
- int cnode[N];
- void readfile()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- if (fopen(Task".inp","r"))
- {
- freopen(Task".inp","r",stdin);
- freopen(Task".out","w",stdout);
- }
- cin >> n >> m;
- for(int i=1; i<=m; i++)
- {
- int u, v;
- cin >> u >> v;
- a[u].pb(v);
- a[v].pb(u);
- }
- }
- void dfs(int u)
- {
- int x = (par[u]!=-1)?1:0;
- int sum = 0;
- child[u] = 1;
- num[u] = low[u] = ++cnt;
- for(auto v : a[u])
- {
- if (v==par[u]) continue;
- if (par[v]) low[u] = min(low[u],num[v]);
- else{
- par[v] = u;
- dfs(v);
- child[u] += child[v];
- low[u] = min(low[u],low[v]);
- if (low[v] >= num[u]){
- x++;
- cnode[u] += child[v]*(child[v]-1);
- sum += child[v];
- }
- }
- }
- if (x>=2){
- cnode[u] += (n-sum-1)*(n-sum-2);
- cnode[u] = n*(n-1)-cnode[u];
- }
- else cnode[u] = (n-1)*2;
- }
- void proc()
- {
- for(int i=1; i<=n; i++)
- {
- if (!num[i])
- {
- par[i] = -1;
- dfs(i);
- }
- }
- for(int i=1; i<=n; i++)
- {
- cout << cnode[i] << '\n';
- }
- }
- signed main()
- {
- readfile();
- proc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement