CF1835D.Doctor's Brown Hypothesis

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The rebels have been crushed in the most recent battle with the imperial forces, but there is a ray of new hope.

Meanwhile, on one of the conquered planets, Luke was getting ready for an illegal street race (which should come as no surprise, given his family history). Luke arrived at the finish line with 88 miles per hour on his speedometer. After getting out of the car, he was greeted by a new reality. It turns out that the battle has not happened yet and will start in exactly kk hours.

The rebels have placed a single battleship on each of the nn planets. mm unidirectional wormholes connect the planets. Traversing each wormhole takes exactly one hour. Generals of the Imperium have planned the battle precisely, but their troops cannot dynamically adapt to changing circumstances. Because of this, it is enough for the rebels to move some ships around before the battle to confuse the enemy, secure victory and change the galaxy's fate.

Owing to numerous strategical considerations, which we now omit, the rebels would like to choose two ships that will switch places so that both of them will be on the move for the whole time (exactly kk hours). In other words, rebels look for two planets, xx and yy, such that paths of length kk exist from xx to yy and from yy to xx.

Because of the limited fuel supply, choosing one ship would also be acceptable. This ship should fly through the wormholes for kk hours and then return to its initial planet.

How many ways are there to choose the ships for completing the mission?

叛军在最近一次与帝国军队的战斗中被彻底击溃,但新的希望之光已然浮现。

与此同时,在一颗已被征服的星球上,卢克正准备参加一场非法街头赛车(鉴于他的家族历史,这并不令人意外)。卢克以时速 88 英里抵达终点线。当他下车后,却迎来了一番全新的现实:原来那场战役尚未发生,且将在恰好 kk 小时后打响。

叛军已在全部 nn 颗星球上各部署了一艘战舰。共有 mm 条单向虫洞连接这些星球,穿越每条虫洞恰好耗时一小时。帝国将军们虽已对战役进行了精确筹划,但其部队无法根据变化的形势动态调整。正因如此,叛军只需在战役开始前将部分战舰重新部署,即可迷惑敌军、确保胜利,并改变银河系的命运。

出于诸多战略考量(此处略去细节),叛军希望选出两艘战舰,使其互换位置,且两艘战舰在整个过程中均处于持续航行状态(即航行时间恰好为 kk 小时)。换言之,叛军需寻找两颗星球 xx 和 yy,使得存在长度为 kk 的路径从 xx 到 yy,同时也存在长度为 kk 的路径从 yy 到 xx。

由于燃料供应有限,仅选择一艘战舰亦可接受。该战舰需经由虫洞连续飞行 kk 小时,随后返回其初始星球。

完成此次任务,共有多少种选择战舰的方式?

输入格式

In the first line of input, there are three integer numbers nn, mm, and kk (1≤n≤1051 \leq n \leq 10^5, 0≤m≤2⋅1050 \leq m \leq 2 \cdot 10^5, n3≤k≤1018n^3 \leq k \leq 10^{18}) denoting respectively the number of planets, wormholes and hours left until the battle starts.

The following mm lines contain two integers each, xx and yy (1≤x,y≤n1 \leq x, y \leq n, x≠yx \ne y), meaning that there is a wormhole from planet xx to planet yy. It is guaranteed that there are no two identical wormholes, i. e. for every two wormholes, either x1≠x2x_1 \neq x_2 or y1≠y2y_1 \neq y_2.

输入的第一行包含三个整数 nn、mm 和 kk(1≤n≤1051 \leq n \leq 10^5,0≤m≤2⋅1050 \leq m \leq 2 \cdot 10^5,n3≤k≤1018n^3 \leq k \leq 10^{18}),分别表示行星数量、虫洞数量以及距离战斗开始剩余的小时数。

接下来的 mm 行每行包含两个整数 xx 和 yy(1≤x,y≤n1 \leq x, y \leq n,x≠yx \ne y),表示存在一条从行星 xx 到行星 yy 的虫洞。保证不存在两条完全相同的虫洞,即对任意两个虫洞,均有 x1≠x2x_1 \neq x_2 或 y1≠y2y_1 \neq y_2。

输出格式

In the first and only line, your program should output the number of possible ways of choosing a pair or a single warship for the mission.

在第一行且唯一的一行中,你的程序应输出为执行任务而选择一对或一艘战舰的可能方案数。

输入输出样例

  • 输入#1

    7 8 346
    1 2
    1 3
    2 4
    3 4
    4 5
    5 1
    6 7
    7 6

    输出#1

    5
  • 输入#2

    5 6 128
    1 2
    1 3
    2 4
    3 4
    4 5
    5 1

    输出#2

    6
  • 输入#3

    3 3 30
    1 2
    2 3
    3 2

    输出#3

    2

说明/提示

In the first sample test, one can choose pairs of ships from the following planets: 22 and 55, 33 and 55, 11 and 44. Individual ships from planets 66 and 77 could also be chosen.

In the second sample test, one can choose a pair of ships from the following planets: 22 and 33. Individual ships from planets 11, 22, 33, 44, and 55 could also be chosen.

In the third sample test, there are no pairs of ships we can choose. Individual ships from planets 22 and 33 could also be chosen.

在第一个样例测试中,可以选择来自以下行星的飞船对:22 和 55、33 和 55、11 和 44。此外,也可以单独选择来自行星 66 和 77 的飞船。

在第二个样例测试中,可以选择来自以下行星的飞船对:22 和 33。此外,也可以单独选择来自行星 11、22、33、44 和 55 的飞船。

在第三个样例测试中,不存在可选的飞船对。此外,也可以单独选择来自行星 22 和 33 的飞船。

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

首页