QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#4557. 温暖会指引我们前行

Statistics

寒冬又一次肆虐了北国大地

无情的北风穿透了人们御寒的衣物

可怜虫们在冬夜中发出无助的哀嚎

“冻死宝宝了!”

这时

远处的天边出现了一位火焰之神

“我将赐予你们温暖和希望!”

只见他的身体中喷射出火焰之力

通过坚固的钢铁,传遍了千家万户

这时,只听见人们欢呼

“暖气来啦!”

任务描述

虽然小R住的宿舍楼早已来了暖气,但是由于某些原因,宿舍楼中的某些窗户仍然开着(例如厕所的窗户),这就使得宿舍楼中有一些路上的温度还是很低。

小R的宿舍楼中有$n$个地点和一些路,一条路连接了两个地点,小R可以通过这条路从其中任意一个地点到达另外一个地点。但在刚开始,小R还不熟悉宿舍楼中的任何一条路,所以他会慢慢地发现这些路,他在发现一条路时还会知道这条路的温度和长度。每条路的温度都是互不相同的。

小R需要在宿舍楼中活动,每次他都需要从一个地点到达另一个地点。小R希望每次活动时经过一条最温暖的路径,最温暖的路径的定义为,将路径上各条路的温度从小到大排序后字典序最大。即温度最低的路温度尽量高,在满足该条件的情况下,温度第二低的路温度尽量高,以此类推。小R不会经过重复的路。由于每条路的温度互不相同,因此只存在一条最温暖的路径。

对于小R的每次活动,你需要求出小R需要走过的路径总长度。如果小R通过当前发现的路不能完成这次活动,则输出 $-1$。

注意本题中的字典序与传统意义上的字典序定义有所不同,对于两个序列$a,b(a \neq b)$,若$a$是$b$的前缀则$a$的字典序较大,同时可以推出空串的字典序最大。

输入格式

第一行两个正整数 $n,m$。表示小R的宿舍楼中有 $n$ 个地点,共发生了 $m$ 个事件。

接下来 $m$ 行,每行描述一个事件,事件分为三类。

  1. $\texttt{find id u v t l}$ 表示小R发现了一条连接$u$和$v$之间的路,编号为$id$。相同$id$的边只会出现一次。

  2. $\texttt{move u v}$ 表示小R要从$u$到达$v$,你需要计算出最温暖的路径的长度 ,若不能从$u$到达$v$,则输出$-1$。

  3. $\texttt{change id l}$ 表示从$u$到$v$这条边的长度变为了$l$(保证在当前时间点这条边存在)。

输出格式

对于每个询问,输出一行整数,表示最温暖的路径长度。

样例一

input

8 19
find 0 0 2 7 2
find 1 2 4 4 4
find 2 4 6 10 1
find 3 6 7 8 6
move 2 7
move 1 6
find 4 2 5 3 4
move 0 5
change 0 12
find 5 4 5 5 10
find 6 2 3 6 9
move 3 5
find 7 0 1 12 1
move 1 6
find 8 1 7 11 100
move 1 6
move 3 7
move 5 6
move 2 2

output

11
-1
6
23
18
106
122
11
0

样例二

input

15 45
find 0 1 0 8 5987
find 1 2 0 14 5455
find 2 3 0 27 8830
find 3 4 3 42 7688
find 4 5 0 25 1756
find 5 6 5 35 1550
find 6 7 4 43 9440
move 3 9
change 2 9113
move 10 13
move 3 3
move 11 10
find 7 8 7 6 7347
find 8 9 8 26 8935
move 8 4
change 3 4466
find 9 10 9 28 8560
move 6 5
find 10 11 10 31 6205
change 9 9228
find 11 12 10 23 948
find 12 13 12 45 5945
move 0 9
move 2 5
change 2 6118
find 13 14 13 12 6906
move 4 1
change 2 504
find 14 4 2 22 9796
move 10 7
move 1 14
move 13 3
find 15 12 9 39 8985
find 16 9 8 17 3710
change 1 5370
find 17 1 0 36 4669
find 18 7 6 37 8087
move 9 0
find 19 14 9 33 8234
find 20 0 4 24 5209
change 1 4883
find 21 6 3 9 2461
find 22 5 2 19 4291
change 1 7219
change 6 4846

output

-1
-1
0
-1
16787
1550
39301
7211
16571
25510
59706
46309
30692

样例三

见下发文件。

限制与约定

对于find操作:$(0\le id\lt m, 0\le u,v \lt n, u\ne v,0\le t\le 1000000000, 0 \le l \le 10000)$;

对于move操作:$(0\le u,v \lt n)$;

对于change操作:$(0 \le l \le 10000)$。

对于100%的数据,$1\le n\le 100000, 1\le m \le 300000$ 。

本题共有20个数据点,每个数据点5分。

测试点$n$$m$其它
$1-2$$\leq20$$\leq50$无特殊约定
$3-5$$\leq1000$$\leq3000$
$6-10$$\leq100000$$\leq300000$所有的find事件都在move事件之前,且没有change事件
$11-14$所有的find事件都在move事件之前
$15-20$无特殊约定
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.