CF788B.Weird journey

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

小男生伊戈尔想成为一名旅行者。起初,他决定游览自己祖国——乌日兰迪亚的所有城市。

众所周知,乌日兰迪亚共有 nn 座城市,由 mm 条双向道路连接。此外,该国不存在两条连接同一对城市的道路,但允许存在起点与终点为同一座城市的道路(即自环边)。伊戈尔希望事先规划自己的旅程。男孩认为一条路径是“好路径”,当且仅当该路径恰好经过 m−2m - 2 条道路两次,而其余 2 条道路各经过一次。“好路径”可以在乌日兰迪亚的任意城市开始和结束。

现在,他想知道乌日兰迪亚中一共有多少条不同的“好路径”。若两条路径所恰好经过一次的道路集合不同,则认为它们是不同的路径。请帮助伊戈尔——计算“好路径”的数量。

输入格式

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.

第一行包含两个整数 nn、mm(1 ≤ n, m ≤ 1061 ≤ n, m ≤ 10^6)—— 分别表示乌日兰迪亚的城巿数量和道路数量。

接下来的 mm 行中,每行包含两个整数 uu 和 vv(1 ≤ u, v ≤ n1 ≤ u, v ≤ n),表示城市 uu 与城市 vv 之间存在一条道路。

保证输入中不会重复给出同一条道路。这也意味着:对任意一座城市,至多只有一条道路连接该城市与其自身(即自环至多一个)。

输出格式

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

输出唯一的整数——乌日兰迪亚中好路径的数量。

输入输出样例

  • 输入#1

    5 4
    1 2
    1 3
    1 4
    1 5

    输出#1

    6
  • 输入#2

    5 3
    1 2
    2 3
    4 5

    输出#2

    0
  • 输入#3

    2 2
    1 1
    1 2

    输出#3

    1

说明/提示

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.

在第一个样例测试用例中,好的路径有:

  • 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.

还存在一些与上述路径“相同”的好路径(因为它们所经过的边集完全一致):

  • 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,
  • 以及所有上述路径的反向路径。

因此,答案为 6。

在第二个测试用例中,Igor 无法遍历所有的道路。

在第三个测试用例中,Igor 恰好每条道路都走一次。

输入解题思路,AI测评打分。不知道怎么写?

首页