#include<bits/stdc++.h>
using namespace std;
const long long maxn=100000+10;
vector<long long>adj[maxn];
vector<long long>allp;
long long n,m,isb[maxn],high[maxn],vis[maxn];
struct dsu{
int par[maxn],wa[maxn];
dsu(){
for(int i=0;i<maxn;i++){
par[i]=i;
wa[i]=0;
}
}
int root(int u){
if(u==par[u]){
return u;
}
return par[u]=root(par[u]);
}
void con(int u,int v){
int rootu=root(u),rootv=root(v);
if(rootu!=rootv){
par[rootv]=rootu;
wa[rootu]+=wa[rootv];
}
}
}ds;
void vorod(){
cin>>n>>m;
for(long long i=0;i<m;i++){
long long u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
}
long long dfspre(long long u=1){
long long ret=high[u];
vis[u]=1;
for(auto x:adj[u]){
if(high[x]!=0){
ret=min(ret,high[x]);
}
}
long long f=0,ted=0;
for(auto x:adj[u]){
if(vis[x]){
continue;
}
ted++;
high[x]=high[u]+1;
long long z=dfspre(x);
if(z>=high[u]){
f=1;
}
ret=min(ret,z);
}
if(u!=1){
isb[u]=f;
if(f){
allp.push_back(u);
}
}else{
if(ted>1){
isb[u]=1;
allp.push_back(u);
}
}
return ret;
}
void pre(){
high[1]=1;
dfspre(1);
vector<pair<long long,long long>>alle;
for(long long i=1;i<=n;i++){
for(auto x:adj[i]){
alle.push_back(make_pair(i,x));
}
adj[i].clear();
if(isb[i]==0){
ds.wa[i]=1;
}
}
for(auto x:alle){
if(isb[x.first]+isb[x.second]==0){
ds.con(x.first,x.second);
}
}
for(auto x:alle){
if(isb[x.first]+isb[x.second]>0){
long long fu=ds.root(x.first);
long long fv=ds.root(x.second);
adj[fu].push_back(fv);
}
}
for(long long i=1;i<=n;i++){
vis[i]=0;
}
}
long long mainres=0;
pair<long long,long long> dfssolve(long long u,long long wa){
pair<long long,long long>ret;
//cout<<u<<" "<<wa<<endl;
ret.second=ret.first=ds.wa[u];
if(isb[u]==1){
ret.first=ret.second=1;
}
vis[u]=1;
for(auto x:adj[u]){
if(vis[x]==0){
pair<long long,long long>fake=dfssolve(x,ret.first);
//cout<<"go: "<<u<<" "<<x<<" "<<isb[u]<<" "<<ds.wa[u]<<" "<<fake.first<<" "<<fake.second<<endl;
ret.second+=fake.second;
if(isb[u]==1){
mainres-=fake.first*((n-fake.second)*(n-fake.second-1));
}
}
}
if(isb[u]==1){
mainres-=wa*ret.second*(ret.second-1);
}
return ret;
}
void solve(){
mainres=1ll*n*(n-1)*(n-2);
dfssolve(1,0);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
//cout.tie(0);
//freopen("inp.txt","r",stdin);
vorod();
pre();
solve();
cout<<mainres<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
23244 KB |
Output is correct |
2 |
Correct |
37 ms |
22988 KB |
Output is correct |
3 |
Incorrect |
31 ms |
18372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5980 KB |
Output is correct |
2 |
Correct |
1 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
1 ms |
5980 KB |
Output is correct |
6 |
Correct |
1 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
1 ms |
5980 KB |
Output is correct |
10 |
Incorrect |
1 ms |
5980 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
17420 KB |
Output is correct |
2 |
Correct |
46 ms |
17476 KB |
Output is correct |
3 |
Correct |
36 ms |
16720 KB |
Output is correct |
4 |
Correct |
34 ms |
16776 KB |
Output is correct |
5 |
Correct |
33 ms |
16244 KB |
Output is correct |
6 |
Correct |
39 ms |
20296 KB |
Output is correct |
7 |
Correct |
37 ms |
20080 KB |
Output is correct |
8 |
Correct |
38 ms |
19528 KB |
Output is correct |
9 |
Correct |
37 ms |
17304 KB |
Output is correct |
10 |
Incorrect |
33 ms |
16896 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5980 KB |
Output is correct |
2 |
Correct |
2 ms |
5940 KB |
Output is correct |
3 |
Incorrect |
2 ms |
5948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
16712 KB |
Output is correct |
2 |
Correct |
39 ms |
15684 KB |
Output is correct |
3 |
Incorrect |
46 ms |
16968 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |