Legacy

题意翻译

Rick 和他的同事们做出了一种新的带放射性的婴儿食品(???根据图片和原文的确如此...),与此同时很多坏人正追赶着他们。因此 Rick 想在坏人们捉到他之前把他的遗产留给 Morty。 在宇宙中一共有 $n$ 个星球标号为 $1 \sim n$。Rick 现在身处于标号为 $s$ 的星球(地球)但是他不知道 Morty 在哪里。 众所周知,Rick 有一个传送枪,他用这把枪可以制造出一个从他所在的星球通往其他星球(也包括自己所在的星球)的单行道路。但是由于他还在用免费版,因此这把枪的使用是有限制的。 默认情况下他不能用这把枪开启任何传送门。在网络上有 $q$ 个售卖这些传送枪的使用方案。每一次你想要实施这个方案时你都可以购买它,但是每次购买后只能使用一次。每个方案的购买次数都是无限的。 网络上一共有三种方案可供购买: - 开启一扇从星球 $v$ 到星球 $u$ 的传送门; - 开启一扇从星球 $v$ 到标号在 $[l,r]$ 区间范围内任何一个星球的传送门。(即这扇传送门可以从一个星球出发通往多个星球) - 开启一扇从标号在 $[l,r]$ 区间范围内任何一个星球到星球 $v$ 的传送门。(即这扇传送门可以从多个星球出发到达同一个星球) Rick 并不知道 Morty 在哪儿,但是 Unity 将要通知他 Morty 的具体位置,并且他想要赶快找到通往所有星球的道路各一条并立刻出发。因此对于每一个星球(包括地球本身)他想要知道从地球到那个星球所需的最小钱数。 ### 输入数据: 输入数据的第一行包括三个整数 $n$,$q$ 和 $s$ 分别表示星球的数目,可供购买的方案数目以及地球的标号。 接下来的 $q$ 行表示 $q$ 种方案。 - 输入 `1 v u w` 表示第一种方案,其中 $v,u$ 意思同上,$w$ 表示此方案价格。 - 输入 `2 v l r w` 表示第二种方案,其中 $v,l,r$ 意思同上,$w$ 表示此方案价格。 - 输入 `3 v l r w` 表示第三种方案,其中 $v,l,r$ 意思同上,$w$ 表示此方案价格。 ### 输出格式: 输出一行用空格隔开的 $n$ 个整数分别表示从地球到第 $i$ 个星球所需的最小钱数。如果不能到达那个星球,输出-1。 说明: 在第一组测试样例里,Rick 可以先购买第 $4$ 个方案再购买第 $2$ 个方案从而到达标号为 $2$ 的星球. 【数据范围】 对于 $100\%$ 的数据,$1\le n,q \le 10^5$,$1\le w \le 10^9$

题目描述

Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are $ n $ planets in their universe numbered from $ 1 $ to $ n $ . Rick is in planet number $ s $ (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF786B/9ce8ffb5132d0e638eaee42e56a9bbc8517d720d.png)By default he can not open any portal by this gun. There are $ q $ plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more. Plans on the website have three types: 1. With a plan of this type you can open a portal from planet $ v $ to planet $ u $ . 2. With a plan of this type you can open a portal from planet $ v $ to any planet with index in range $ [l,r] $ . 3. With a plan of this type you can open a portal from any planet with index in range $ [l,r] $ to planet $ v $ . Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.

输入输出格式

输入格式


The first line of input contains three integers $ n $ , $ q $ and $ s $ ( $ 1<=n,q<=10^{5} $ , $ 1<=s<=n $ ) — number of planets, number of plans and index of earth respectively. The next $ q $ lines contain the plans. Each line starts with a number $ t $ , type of that plan ( $ 1<=t<=3 $ ). If $ t=1 $ then it is followed by three integers $ v $ , $ u $ and $ w $ where $ w $ is the cost of that plan ( $ 1<=v,u<=n $ , $ 1<=w<=10^{9} $ ). Otherwise it is followed by four integers $ v $ , $ l $ , $ r $ and $ w $ where $ w $ is the cost of that plan ( $ 1<=v<=n $ , $ 1<=l<=r<=n $ , $ 1<=w<=10^{9} $ ).

输出格式


In the first and only line of output print $ n $ integers separated by spaces. $ i $ -th of them should be minimum money to get from earth to $ i $ -th planet, or $ -1 $ if it's impossible to get to that planet.

输入输出样例

输入样例 #1

3 5 1
2 3 2 3 17
2 3 2 2 16
2 2 2 3 3
3 3 1 1 12
1 3 3 17

输出样例 #1

0 28 12 

输入样例 #2

4 3 1
3 4 1 3 12
2 2 3 4 10
1 2 4 16

输出样例 #2

0 -1 -1 12 

说明

In the first sample testcase, Rick can purchase $ 4 $ th plan once and then $ 2 $ nd plan in order to get to get to planet number $ 2 $ .