#P6348. [PA 2011] Journeys

    ID: 7100 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011线段树O2优化最短路PA(波兰)

[PA 2011] Journeys

Problem Description

On a planet, there are nn countries and many bidirectional roads. The countries are numbered from 11 to nn.

However, there are too many roads to describe in the usual way. So we describe the roads as follows: (a,b),(c,d)(a,b),(c,d) means that for any two countries x,yx,y, if axba \le x \le b and cydc \le y \le d, then there is a road between xx and yy.

The capital is located in country PP. You want to know the minimum number of roads that must be taken to travel from country PP to any country. It is guaranteed that country PP can reach every country.

Input Format

The first line contains three integers n,m,Pn,m,P.

Then follow mm lines, each containing four integers a,b,c,da,b,c,d.

Output Format

Output nn lines. The ii-th line should contain the minimum number of roads that must be taken to travel from country PP to country ii.

5 3 4
1 2 4 5
5 5 4 4
1 1 3 3
1
1
2
0
1

Hint

For all testdata, it is guaranteed that 1n5×1051 \le n \le 5 \times 10^5, 1m1051 \le m \le 10^5, 1abn1 \le a \le b \le n, 1cdn1 \le c \le d \le n.

Translated by ChatGPT 5