#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;
#define ll long long
#define int long long
const int N=1e6+10;
int fa[N],vis[N];
int find(int x){
if(fa[x]==x) return x;
else return fa[x]=find(fa[x]);
}
int n,m,a[N],b[N],in[N];
int32_t main(){
scanf("%lld%lld",&n,&m);for(int i=1;i<=n;i++) fa[i]=i;
int cl=0;
for(int i=1;i<=m;i++) {
scanf("%lld%lld",&a[i],&b[i]);
vis[a[i]]=vis[b[i]]=1;
int fx=find(a[i]),fy=find(b[i]);
if(a[i]==b[i]){
++cl;
}else{
in[a[i]]++;in[b[i]]++;
}
if(fx!=fy){
fa[fx]=fy;
}
}
int cnt=0;
for(int i=1;i<=n;i++){
if(fa[i]==i&&vis[i]) ++cnt;
}
if(cnt!=1) return cout<<0<<endl,0;
int res=0;
for(int i=1;i<=m;i++){
if(a[i]==b[i]) res+=m-1;
else{
res+=in[a[i]]+in[b[i]]-2+cl;
}
}
cout<<res/2<<endl;
}
|