日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑)

發(fā)布時(shí)間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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.

題目大意:

小男孩Igor想成為一名旅行者。起初,他決定訪問他祖國?— Uzhlyandia的所有城市。

眾所周知,Uzhlyandia有?n?座城市,用?m?條無向邊連接起來。 此外,沒有兩條道路連接同一對城市,但道路開始和結(jié)束在同一個(gè)城市可以存在。Igor想事先計(jì)劃好他的旅行。男孩認(rèn)為好的路徑經(jīng)過?m?-?2?條邊恰好兩次,經(jīng)過?2?條邊恰好一次, 這條路徑的起點(diǎn)和終點(diǎn)可以在?n?個(gè)城市中任選。

現(xiàn)在他想知道有多少條不同的路徑滿足要求。注意,經(jīng)過點(diǎn)順序不同,每條邊經(jīng)過次數(shù)相同的路徑為同一條路徑。

Input

第一行包含兩個(gè)整數(shù)?n,?m?(1?≤?n,?m?≤?106)?— Uzhlyandia的城市和道路的數(shù)量。

之后?m?行包含兩個(gè)整數(shù)?u?和?v?(1?≤?u,?v?≤?n) 表示城市?u?和?v之間有一條路徑。

保證沒有重邊,但可能有自環(huán)。

解題報(bào)告:

貼一個(gè)題解:m-2條邊走兩次,2條邊走一次,那么我們可以把每一條邊都復(fù)制一遍,然后再刪掉兩條邊,求歐拉通路的方案數(shù)。

另一種思考方式:假設(shè)走一次的這兩條邊稱為關(guān)建邊,那么需要發(fā)現(xiàn)你選的這兩條關(guān)建邊,一定連在一個(gè)頂點(diǎn)上。所以枚舉每個(gè)點(diǎn)C(n,2)統(tǒng)計(jì)一下,然后對于自環(huán)單獨(dú)容斥處理一下即可。

當(dāng)然,對于不連通的圖,直接輸出0就可以了。但是這里有坑,就是他雖然不連通,但是如果獨(dú)立出去的分量都是獨(dú)立的點(diǎn)的話,是沒有關(guān)系的,因?yàn)樗麄儾]有邊相連。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e6 + 5; vector<int> vv[MAX]; int n,m,f[MAX],vis[MAX],cnt; void dfs(int x,int fa) {vis[x] = 1;for(auto v : vv[x]) {if(vis[v] || v == fa) continue;dfs(v,x);} } int main() {cin>>n>>m;for(int u,v,i = 1; i<=m; i++) {scanf("%d%d",&u,&v);if(u == v) vv[u].pb(v);else vv[u].pb(v),vv[v].pb(u);}for(int i = 1; i<=n; i++) sort(vv[i].begin(),vv[i].end()),f[i]=i;ll ans = 0; for(int i = 1; i<=n; i++) {if(vv[i].size() > 0) {dfs(i,0);break;}}for(int i = 1; i<=n; i++) {if(vis[i] == 0 && vv[i].size() > 0) return 0,puts("0");}for(int i = 1; i<=n; i++) {int ok = binary_search(vv[i].begin(),vv[i].end(),i);cnt += ok;ll tmp = vv[i].size() - ok;ans += tmp*(tmp-1)/2;}printf("%lld\n",ans +1LL*cnt*(m-1) - 1LL*cnt*(cnt-1)/2);return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 韩国主播青草200vip视频 | 欧美在线一二 | 国产污视频在线看 | 中文字幕网站 | 伊是香蕉大人久久 | 久久77 | 电影91久久久 | 久草97| 亚洲一级无毛 | 男女操操视频 | 三级福利 | 久久久午夜精品 | 国产极品一区二区 | 亚洲色图28p | 亚洲欧美另类视频 | 无人在线观看的免费高清视频 | 国产美女作爱全过程免费视频 | 777亚洲 | 欧美亚洲久久 | 福利姬在线播放 | 日本中文字幕在线视频 | 久久99久久99精品免视看婷婷 | 男女又爽又黄 | 97超碰碰碰| 91禁蘑菇在线看 | 国产在线自 | 亚洲精品无码不卡在线播he | 99ri在线| 人妻丰满熟妇av无码区不卡 | 国产网址 | 欧美日韩激情一区二区 | 国产成人 综合 亚洲 | 六月丁香啪啪 | 国产情侣久久久久aⅴ免费 caoporn成人 | 五月婷婷激情五月 | 一区二区有码 | 男女啪啪网站免费 | 老司机免费精品视频 | 18禁裸男晨勃露j毛免费观看 | 中文字幕一区二区在线播放 | 东方av正在进入 | 欧美一卡二卡在线 | 免费看毛片的网站 | 色婷婷av一区二区三区大白胸 | 日本一本高清 | 欧美精品国产精品 | 香蕉视频色版 | 午夜毛片在线观看 | 黄色小视频免费 | 日韩深夜视频 | 青青草原av在线 | 国产精品免费无遮挡无码永久视频 | 欧美区国产区 | 亚洲av无码一区二区三区人 | 伊人精品视频 | 黄色大片国产 | 91av在线视频观看 | 91丝袜一区在线观看 | 亚欧精品在线 | 成人影音在线 | 97av.com| 精品一区二区三区蜜臀 | 日韩一级高清 | 国产少妇在线 | 福利视频不卡 | 欧美 日韩 中文 | 午夜h| 麻豆国产一区二区三区四区 | 国精产品一区一区三区有限公司杨 | 国产 第1190页 | 国产一二三在线视频 | 亚洲国产精品无码专区 | 日韩中文字幕av在线 | 蜜桃视频久久 | 国产夫妻在线视频 | 一级黄色a视频 | 久久夜精 | 美景之屋电影免费高清完整韩剧 | 亚日韩欧美 | 久久免费看毛片 | 天天av天天操 | 4hu在线观看 | 一区二区中文在线 | 91免费.| 精品久久99 | 丰满大乳国产精品 | av大帝| 国产一区二区三区在线观看 | 91久久久久国产一区二区 | 国产在线观看第一页 | 99re8在线精品视频免费播放 | 国产精品久久久久久久久久小说 | 久久久久国产精品区片区无码 | 国产一区麻豆 | 亚洲精品一区二区三区在线观看 | 国产又爽又色 | 韩国日本在线观看 | 在线观看国产黄色 | 青草操|