CF786B

Legacy

省选/NOI−

题目描述

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 nn planets in their universe numbered from 11 to nn . Rick is in planet number ss (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.

By default he can not open any portal by this gun. There are qq 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 vv to planet uu .
  2. With a plan of this type you can open a portal from planet vv to any planet with index in range [l,r][l,r] .
  3. With a plan of this type you can open a portal from any planet with index in range [l,r][l,r] to planet vv .

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 nn , qq and ss ( 1<=n,q<=1051<=n,q<=10^{5} , 1<=s<=n1<=s<=n ) — number of planets, number of plans and index of earth respectively.

The next qq lines contain the plans. Each line starts with a number tt , type of that plan ( 1<=t<=31<=t<=3 ). If t=1t=1 then it is followed by three integers vv , uu and ww where ww is the cost of that plan ( 1<=v,u<=n1<=v,u<=n , 1<=w<=1091<=w<=10^{9} ). Otherwise it is followed by four integers vv , ll , rr and ww where ww is the cost of that plan ( 1<=v<=n1<=v<=n , 1<=l<=r<=n1<=l<=r<=n , 1<=w<=1091<=w<=10^{9} ).

输出格式

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

输入输出样例

输入样例 #1

text
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

text
0 28 12

输入样例 #2

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

输出样例 #2

text
0 -1 -1 12

说明/提示

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

🚀 提交评测

登录并绑定洛谷账号后即可在此在线提交代码并实时评测。

前往登录

💡 题解 (0)

登录后即可撰写并分享您的解题思路。

暂无题解,快来发布全站第一篇题解吧!

💬 题目讨论 (0)

登录后可以发起或参与讨论。

暂无讨论内容。

📊 题目信息

题号CF786B
难度省选/NOI−
时间限制2000 ms
内存限制250 MB
题目来源洛谷题库
算法标签
线段树图论建模最短路

⚡ 快速操作

在线提交代码在洛谷打开原题 ↗