Under construction

Still being built. Things may change

Take the Plane

Time limit2sMemory limit1024 MB

Summary
Find the cheapest total ticket cost to reach each city from city K, where each single-use ticket covers a rectangle of allowed departure and arrival city ranges.
Level

Medium7 of 10

Topics
Shortest path, Segment tree, Union-find
Solved
No attempts yet

Problem

Have you heard of Gyeonggwak, a country where only people good at computer science may live? Gyeonggwak has NN cities, numbered from 1 to NN.

The only way to travel between cities in Gyeonggwak is by airplane. For every pair of cities, a flight passes between the two. However, boarding a flight requires an airplane ticket. Gyeonggwak sells MM tickets, numbered from 1 to MM. Ticket ii costs AiA_i won and can be used only when the departure city number is between BiB_i and CiC_i inclusive, and the arrival city number is between DiD_i and EiE_i inclusive (1≤i≤M1 \le i \le M).

Each of the MM tickets is single-use and can be bought only once.

Junjun's house is in city KK. Right now, Junjun is staying at home.

Let WXW_X be the minimum total cost of tickets Junjun must buy to travel from his house to city XX (1≤X≤N1 \le X \le N). Junjun buys all the necessary tickets before leaving home. If no way of buying tickets lets him reach city XX, define WX=−1W_X = -1.

Write a program that computes all of W1,⋯ ,WNW_1, \cdots, W_N.

Input

The first line contains three integers NN, MM, and KK, separated by spaces.

From the second line onward, the next MM lines describe the tickets. Line (i+1)(i+1) contains five integers AiA_i, BiB_i, CiC_i, DiD_i, and EiE_i, separated by spaces (1≤i≤M1 \le i \le M).

Output

Print NN integers W1,⋯ ,WNW_1, \cdots, W_N on one line, separated by spaces.

Note that WK=0W_K = 0.

Constraints

  • 1≤N≤250,0001 \le N \le 250{,}000
  • 1≤M≤250,0001 \le M \le 250{,}000
  • 1≤K≤N1 \le K \le N
  • 0≤Ai≤1090 \le A_i \le 10^9 (1≤i≤M1 \le i \le M)
  • 1≤Bi≤Ci≤N1 \le B_i \le C_i \le N (1≤i≤M1 \le i \le M)
  • 1≤Di≤Ei≤N1 \le D_i \le E_i \le N (1≤i≤M1 \le i \le M)

Examples3

  1. Example 1

    Input
    1 1 1
    0 1 1 1 1
    
    Expected output
    0
    
  2. Example 2

    Input
    3 1 1
    10 1 2 3 3
    
    Expected output
    0 -1 10
    
  3. Example 3

    Input
    5 2 1
    5 2 3 4 5
    5 1 5 2 2
    
    Expected output
    0 5 -1 10 10