QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#16707. 王国与改革

Statistiques

在 Berland 王国中,有 $n$ 个城市和 $m$ 条连接某些城市对的双向道路。 政府长期以来并不关心道路系统,因此道路的建设毫无章法。例如,可能有多条道路连接同一对城市,甚至一个城市可能有一条连接到自身的自环道路(甚至多条)。此外,整个国家可能根本不是连通的,也就是说,对于某些城市对,可能无法通过道路从一个城市到达另一个城市。不用说,所有的道路都处于非常糟糕的状态,急需修缮。

最近任命了一位新的交通部长,负责道路系统的改造。部长并不想新建任何道路,也不想拆除任何旧道路,因为市民们已经习惯了现有的道路系统,无论它有多么糟糕。部长设想的改造方案是将每条现有的道路改建为现代汽车高速公路或高速铁路。为了避免反垄断调查,部长必须确保每个城市都至少有一条相邻的高速公路和至少一条相邻的铁路。请帮助部长为每条道路选择新的类型,以满足这一条件,或者确定这是不可能实现的。

输入格式

第一行包含两个整数 $n$ 和 $m$($1 \le n \le 300\,000$,$0 \le m \le 300\,000$),分别表示城市数量和道路数量。

接下来的 $m$ 行描述这些道路。其中第 $i$ 行包含两个整数 $u_i, v_i$($1 \le u_i, v_i \le n$),表示第 $i$ 条道路连接的城市编号。

请注意,允许存在重边(多条道路连接同一对城市)和自环(道路连接城市自身),并且不保证所有城市在道路网络中都是连通的。

输出格式

如果存在满足条件的道路类型分配方案,输出一个长度为 $m$ 的字符串。如果第 $i$ 条道路应改建为高速公路,则该字符串的第 $i$ 个字符应为 "H";如果应改建为铁路,则应为 "T"。如果存在多种可能的分配方案,输出其中任意一种即可。

如果不存在满足条件的分配方案,输出唯一的字符串 "Impossible"。

样例

输入 1

3 4
1 2
1 3
2 3
2 3

输出 1

HTHT

输入 2

3 1
1 2

输出 2

Impossible

输入 3

3 4
1 1
1 1
2 3
3 2

输出 3

HTHT

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.