#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define int ll
#define all(v) v.begin(),v.end()
#define sz(s) ((int)s.size())
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
const ll inf=1e18;
const int MAX=2e5+10;
const int mod=1e9+7;
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
int n,m;
vector<int> g[MAX];
int tin[MAX],timer;
int fup[MAX];
bool use[MAX],cutPoint[MAX];
stack<int> st;
vector<int> ver[MAX];
int cmp[MAX],cnt;
void dfs(int v,int p=-1){
st.push(v);
tin[v]=fup[v]=++timer;
use[v]=1;
int children=0;
for(auto to:g[v]){
if(to==p)continue;
if(!use[to]){
children++;
dfs(to,v);
fup[v]=min(fup[v],fup[to]);
if(fup[to]>=tin[v]){
cutPoint[v]=(p!=-1);
ver[++cnt].pb(v);
while(ver[cnt].back()!=to){
ver[cnt].pb(st.top());
st.pop();
}
}
}
else fup[v]=min(fup[v],tin[to]);
}
if(p==-1&&children>1){
cutPoint[v]=1;
}
}
int ans;
int zs[MAX];
vector<vector<int>> t;
void calc(int v,int p=-1){
int in=zs[v];
ans+=in*(in-1)*(in-2);
ans+=2*in*(in-1)*(n-in);
if(in>=2)ans+=sz(t[v])*in*(in-1);
// cout<<v<<" "<<zs[v]<<"\n";
// cout<<v<<" "<<2*in*(in-1)*(n-in)<<"\n";
for(auto to:t[v]){
if(to==p)continue;
calc(to,v);
zs[v]+=zs[to];
}
// cout<<v<<" "<<n-zs[v]<<" "<<zs[v]-in<<" "<<in<<"\n";
ans+=(n-zs[v])*(zs[v]-in)*in;
for(auto to:t[v]){
if(to==p)continue;
// cout<<v<<" "<<zs[to]<<" "<<n-zs[to]-in<<" "<<in<<"\n";
ans+=zs[to]*(n-zs[to]-in)*in;
}
}
void bct(){
for(int i=1;i<=n;i++){
if(!use[i])dfs(i);
}
int ck=0;
for(int i=1;i<=n;i++){
if(cutPoint[i]){
zs[ck]=1;
cmp[i]=ck++;
t.pb({});
}
}
// cout<<cnt<<" "<<cutPoint[1]<<"\n";
for(int i=1;i<=cnt;i++){
t.pb({});
for(int v:ver[i]){
if(!cutPoint[v]){
cmp[v]=ck;
zs[ck]++;
}
else{
t[cmp[v]].pb(ck);
t[ck].pb(cmp[v]);
}
}
ck++;
}
// for(int i=0;i<sz(t);i++){
// cout<<zs[i]<<" ";
// }
// cout<<"\n";
for(int i=0;i<sz(t);i++){
sort(all(t[i]));
t[i].erase(unique(all(t[i])),t[i].end());
}
calc(0);
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
bct();
cout<<ans<<"\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
29636 KB |
Output is correct |
2 |
Correct |
42 ms |
29636 KB |
Output is correct |
3 |
Incorrect |
60 ms |
33152 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12368 KB |
Output is correct |
2 |
Correct |
3 ms |
12240 KB |
Output is correct |
3 |
Correct |
3 ms |
12368 KB |
Output is correct |
4 |
Correct |
4 ms |
12368 KB |
Output is correct |
5 |
Correct |
3 ms |
12624 KB |
Output is correct |
6 |
Correct |
3 ms |
12384 KB |
Output is correct |
7 |
Correct |
4 ms |
12368 KB |
Output is correct |
8 |
Correct |
4 ms |
12536 KB |
Output is correct |
9 |
Correct |
4 ms |
12368 KB |
Output is correct |
10 |
Incorrect |
5 ms |
12340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
34664 KB |
Output is correct |
2 |
Correct |
63 ms |
34796 KB |
Output is correct |
3 |
Correct |
69 ms |
34604 KB |
Output is correct |
4 |
Correct |
91 ms |
34776 KB |
Output is correct |
5 |
Correct |
78 ms |
34752 KB |
Output is correct |
6 |
Correct |
88 ms |
44228 KB |
Output is correct |
7 |
Correct |
73 ms |
41156 KB |
Output is correct |
8 |
Correct |
73 ms |
38404 KB |
Output is correct |
9 |
Correct |
69 ms |
36664 KB |
Output is correct |
10 |
Incorrect |
68 ms |
34780 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12368 KB |
Output is correct |
2 |
Correct |
4 ms |
12368 KB |
Output is correct |
3 |
Incorrect |
4 ms |
12368 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
34748 KB |
Output is correct |
2 |
Correct |
70 ms |
34232 KB |
Output is correct |
3 |
Incorrect |
58 ms |
29880 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |