D. Weird journey
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.

It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads in the country that connect the same pair of cities, but roads starting and ending in the same city can exist. Igor wants to plan his journey beforehand. Boy thinks a path is good if the path goes over m - 2 roads twice, and over the other 2 exactly once. The good path can start and finish in any city of Uzhlyandia.

Now he wants to know how many different good paths are in Uzhlyandia. Two paths are considered different if the sets of roads the paths goes over exactly once differ. Help Igor — calculate the number of good paths.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 106) — the number of cities and roads in Uzhlyandia, respectively.

Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) that mean that there is road between cities u and v.

It is guaranteed that no road will be given in the input twice. That also means that for every city there is no more than one road that connects the city to itself.

Output

Print out the only integer — the number of good paths in Uzhlyandia.

Examples
Input
5 4
1 2
1 3
1 4
1 5
Output
6
Input
5 3
1 2
2 3
4 5
Output
0
Input
2 2
1 1
1 2
Output
1
Note

In first sample test case the good paths are:

  • 2 → 1 → 3 → 1 → 4 → 1 → 5,
  • 2 → 1 → 3 → 1 → 5 → 1 → 4,
  • 2 → 1 → 4 → 1 → 5 → 1 → 3,
  • 3 → 1 → 2 → 1 → 4 → 1 → 5,
  • 3 → 1 → 2 → 1 → 5 → 1 → 4,
  • 4 → 1 → 2 → 1 → 3 → 1 → 5.

There are good paths that are same with displayed above, because the sets of roads they pass over once are same:

  • 2 → 1 → 4 → 1 → 3 → 1 → 5,
  • 2 → 1 → 5 → 1 → 3 → 1 → 4,
  • 2 → 1 → 5 → 1 → 4 → 1 → 3,
  • 3 → 1 → 4 → 1 → 2 → 1 → 5,
  • 3 → 1 → 5 → 1 → 2 → 1 → 4,
  • 4 → 1 → 3 → 1 → 2 → 1 → 5,
  • and all the paths in the other direction.

Thus, the answer is 6.

In the second test case, Igor simply can not walk by all the roads.

In the third case, Igor walks once over every road.

题意:n个点 m条路 问你有多少条好路(有自环的情况)

好路就是走过所有点 m-2条路走2遍 剩下两条路走一遍

我开始有点懵 后来发现只要是联通的  那么就可以满足这个条件  问题是选两条路走一遍

自环t1 其他 t2

1》两条都不是自环的  那么这两条一定有公共点

for(int i=1;i<=n;i++)ans=ans+a[i]*(a[i]-1)/2;

2》一条有自环  一条不是 t1*t2;

3》都是自环  t1*(t1-1)/2

开始edge[N]开小了  无限wa  懵比了

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<queue>
#include<cstring>
#include<string.h>
#include<algorithm>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
int m,n;
int flag[N];
int head[N];
int vis[N];
ll a[N],b[N];
int cnt=;
void init(){
memset(vis,,sizeof(vis));
cnt=;
memset(head,-,sizeof(head));
}
struct node{
int to,next;
}edge[N*+];
void add(int u,int v){
edge[cnt].to=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void DFS(int x){
vis[x]=;
for(int i=head[x];i!=-;i=edge[i].next){
int v=edge[i].to;
if(vis[v]==){
DFS(v);
}
}
}
int main(){
scanf("%d%d",&n,&m);
init();
ll t1=;
ll t2=;
int u,v;
memset(a,,sizeof(a));
for(int i=;i<m;i++){
scanf("%d%d",&u,&v);
b[u]=b[v]=;
if(u!=v){add(u,v);add(v,u);t1++;a[u]++;a[v]++;}
else
t2++;
}
DFS(u);
for(int i=;i<=n;i++){
if(vis[i]==&&b[i]){
cout<<<<endl;
return ;
}
}
ll ans=;
ans=ans+t1*t2;
ans=ans+(t2*(t2-))/;
for(int i=;i<=n;i++)
ans=ans+(a[i]*(a[i]-))/;
printf("%I64d\n",ans);
}

最新文章

  1. 如何解决wow.js与fullpage的兼容性
  2. jQuery系列:五个模块总结
  3. [OC][转]UITableView属性及方法大全
  4. Arduino101学习笔记(七)&mdash;&mdash; 时间API
  5. dbVisualizer连接mysql
  6. 如何配置magento免运费商品方法
  7. DEDECMS中,channelartlist标签
  8. MFC关于VS内存释放的定位
  9. web.xml 3.0头部模板
  10. [原]创建三个输入文本框,当光标离开文本框的时候如果文本框为空,则将文本框背景色设置为红色,如果不为空则为白色。提示:焦点进入控件的事件是onfocus,焦点离开控件的事件是onblur
  11. 新一代开源Android渠道包生成工具Walle
  12. mysql 数据库导出与导入
  13. 每天一个linux命令:chgrp
  14. android ------- 运行官方NDK 案例HelloJNI
  15. 剑指OFFER例题——从尾到头打印链表
  16. X11 fluxbox窗口管理器
  17. TFlearn——(1)notMNIST
  18. 上云、微服务化和DevOps,少走弯路的办法
  19. ModelAttribute注解使用与spring重定向传参
  20. axure rp8.1 注册码

热门文章

  1. linux下tomcat启动正常,但是外部浏览器无法访问
  2. 使用jQuery的toggle()方法对HTML标签进行显示、隐藏操作
  3. #1003 Max Sum
  4. linux 汇编 - 函数调用
  5. 【sqli-labs】 less60 GET -Challenge -Double Query -5 queries allowed -Variation3 (GET型 挑战 双查询 只允许5次查询 变化3)
  6. (转)OL2中设置鼠标的样式
  7. parseInt()函数
  8. Python 发送邮件、加密 day5
  9. JS页面跳转和js对iframe进行页面跳转、刷新
  10. JAVA正则表达式matcher.find()和 matcher.matches()的区别