QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 960 MB Total points: 100 Hackable ✓

#15841. Tic-Tac-Toe on a Graph

الإحصائيات

图上的井字棋

菲律宾的小学生们喜欢在课间休息时在教室的黑板或他们带到数学课上的小白板上玩游戏。Alice 和 Bob 曾经很喜欢玩井字棋,但自从他们了解到这是一个已被破解的游戏后,就对它感到厌倦了。现在,他们想通过在图上玩这个游戏来进行创新!

他们在白板上画了 $n$ 个方格(编号为 1 到 $n$),并画了 $m$ 条线,每条线连接一对不同的方格(用专业术语来说,他们画了一个简单的无向无权图,其中方格是顶点,线是边)。最初,所有方格都是空的。

Alice 和 Bob 将轮流进行游戏;Alice 总是先手。在 Alice 的回合,她选择一个空方格并画一个 X。在 Bob 的回合,他选择一个空方格并画一个 O。

他们仍然很容易感到厌倦,所以游戏在五步之后结束。因此,Alice 总共有三次回合,Bob 总共有两次回合。

如果 Alice 能凑成“三个 X 连成一线”,她就赢了。形式化地说,Alice 画 X 的三个方格必须在图中构成一条长度为 3 的路径(注意,路径中顶点的顺序不一定必须与她填充这些方格的顺序一致)。如果 Bob 能阻止这种情况,Bob 就赢了。

Alice 对哪些起始移动能让她必胜感兴趣,假设她和 Bob 在那次首步移动之后都采取最优策略。如果存在一种策略(在那次首步移动之后),无论 Bob 如何应对,Alice 都能获胜,那么 Alice 就是“必胜”的。

例如,考虑下图。

如果 Alice 在第一步选择在 1 号方格画 X,那么无论 Bob 如何应对,她都能必胜。以下是其中一种可能的游戏过程:

  • Alice 在 1 号方格画 X
  • Bob 在 4 号方格画 O
  • Alice 在 2 号方格画 X
  • Bob 在 3 号方格画 O
  • Alice 在 7 号方格画 X

Alice 获胜,因为她通过 1、2 和 7 凑成了三个连成一线的 X。

请注意,展示这局游戏不足以证明 Alice 总是获胜;你必须证明无论 Bob 怎么做,她都有获胜的路径。不过在这种情况下,Alice 在第一步选择 1 号方格后确实可以必胜。相信我们 ;)

我们可以证明,如果 Alice 的起始移动是 1、2、3、4 或 5 中的一个,她就可以必胜。另一方面,如果她的起始移动是 6、7 或 8 中的一个,她则注定会输。

给定图,确定有多少种起始移动能让 Alice 获胜。

输入格式

输入的第一行包含两个用空格分隔的整数 $n$ 和 $m$。

接下来 $m$ 行描述边。每行包含两个用空格分隔的整数 $u$ 和 $v$,表示连接方格 $u$ 和 $v$ 的一条线。

输出格式

输出一个整数,表示 Alice 必胜的起始移动数量。

数据范围

$5 \le n \le 2 \times 10^5$ $0 \le m \le \min(2 \times 10^5, n(n - 1)/2)$ $1 \le u, v \le n$(对于每条边) 每条边连接两个不同的顶点,且任意一对顶点之间最多只有一条边。

样例

输入 1

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

输出 1

5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.