QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 2048 MB Puntuación total: 100

#16033. 阿曼达休息室

Estadísticas

H. A. Hansen, cc-by-sa

AMANDA AIR 在许多不同的机场之间设有航线。他们询问了其最重要的常旅客(AA 常旅客计划的会员)最常乘坐哪些航线。根据这项调查,首席执行官兼所有者 Amanda 得出结论:AMANDA AIR 将在他们运营的部分机场设立贵宾室。

然而,由于在各种不同的机场之间有如此多的航线,她雇佣你来确定在满足她设定的约束条件的前提下,最少需要建造多少个贵宾室(如果可能的话)。你需要在建造任何贵宾室之前提供这个计算结果。她的要求规定:对于某些航线,两个机场都必须设有贵宾室;对于另一些航线,必须在其中恰好一个机场设有贵宾室;而对于某些航线,两个机场都不能设有贵宾室。

她非常有经济头脑,要求建造的贵宾室总数绝对最少。

输入格式

第一行包含两个非负整数 $1 \le n, m \le 200\,000$,分别表示 Amanda 目录中的机场数量和航线数量。

接下来有 $m$ 行,每行通过三个非负整数 $1 \le a, b \le n$ 和 $c \in \{0, 1, 2\}$ 描述一条航线,其中 $a$ 和 $b$ 是该航线连接的机场,$c$ 是贵宾室的数量。

没有航线会将机场与自身相连,且对于任意两个机场,最多给出一条关于该航线的要求。

正如所预期的,0 表示两个机场都不设贵宾室,1 表示在两个机场中恰好有一个设立贵宾室,2 表示在两个机场都设立贵宾室。

输出格式

如果可以满足所有要求,输出所需的最少贵宾室数量。如果不可能满足,输出 impossible

样例

输入样例 1

4 4
1 2 2
2 3 1
3 4 1
4 1 2

输出样例 1

3

输入样例 2

5 5
1 2 1
2 3 1
2 4 1
2 5 1
4 5 1

输出样例 2

impossible

输入样例 3

4 5
1 2 1
2 3 0
2 4 1
3 1 1
3 4 1

输出样例 3

2

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.