QOJ.ac

QOJ

Time Limit: 15 s Memory Limit: 256 MB Total points: 100

#1072. 冬日道路

Statistics

冬日将至,临冬城的居民们正在为漫长的寒冬做准备。道路和桥梁的稳定性是他们特别关心的问题;随着季节的推移,补给线必须保持畅通。

临冬城的土木工程师们希望对道路损毁和需要进行的维修情况进行建模。在他们的模型中,每条道路连接城市中的两个地标,且每条道路都有一定的承载能力。卡车在地标之间行驶,只能通过足够坚固的道路。具体来说,一辆重量为 $w$ 的补给卡车可以通过承载能力为 $c$ 的道路,当且仅当 $w \le c$。无论是自然原因还是意外事故,道路的承载能力都会随时间下降。此外,维修可以提高道路的承载能力。在道路状况不断变化的同时,补给卡车仍需能够从起点到达目的地,工程师们希望测试卡车是否仍然能够完成地标之间的特定运输任务。

给定一系列道路变化和补给卡车的运输任务,请帮助工程师检查在寒冬来临时,补给是否仍然能够送达。

输入格式

输入包含多组测试数据。每组测试数据的第一行包含两个整数 $n, m$ ($1 \le n \le 1,000, 1 \le m \le 100,000$),其中 $n$ 是地标的数量,$m$ 是连接它们的路数。接下来 $m$ 行,每行包含三个整数 $a, b, c$ ($1 \le a, b \le n$ 且 $1 \le c \le 1,000,000,000$),表示连接地标 $a$ 和 $b$ 的一条承载能力为 $c$ 的道路。道路按输入顺序编号为 $1, 2, 3, \dots, m$。

接下来一行包含一个整数 $e$ ($1 \le e \le 100,000$),表示事件的数量。随后有 $e$ 行,每行由一个大写字母和若干整数组成:

  • B r c:表示道路 $r$ 损坏。其承载能力降低至 $c$。($1 \le r \le m, 1 \le c < 1,000,000,000$)
  • R r c:表示道路 $r$ 得到维修。其承载能力提高至 $c$。($1 \le r \le m, 1 < c \le 1,000,000,000$)
  • S a b w:检查重量为 $w$ 的补给卡车是否能从地标 $a$ 行驶到地标 $b$。($1 \le a, b \le n, 1 \le w \le 1,000,000,000$)

输入中只会出现大写字母 B、R 或 S。所有事件按输入给定的顺序发生。输入中最多有 2,000 次损坏/维修事件。输入以一行两个 0 结束。

输出格式

对于每个 S a b w 查询,按顺序输出结果:如果存在一条从 $a$ 到 $b$ 且能支撑重量为 $w$ 的卡车的路径,则输出 1,否则输出 0。每个数字单独占一行,不要包含空格。输出之间不要打印任何空行。

样例

样例输入 1

3 4
1 2 3
2 3 3
2 1 1
1 2 1
6
S 1 2 4
S 2 3 2
R 1 4
S 1 2 4
B 2 1
S 2 3 2
0 0

样例输出 1

0
1
1
0

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.