#543
Unrated
Tickets
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie is going on a hiking excursion! The trail that she is currently traversing consists of NN checkpoints labeled 1N1\ldots N (1N1051\le N\le 10^5).

There are KK (1K1051\le K\le 10^5) tickets available for purchase. The ii-th ticket can be purchased at checkpoint cic_i (1ciN1\le c_i\le N) for price pip_i (1pi1091\le p_i\le 10^9) and provides access to all of checkpoints [ai,bi][a_i,b_i] (1aibiN1\le a_i\le b_i\le N). Before entering any checkpoint, Bessie must have purchased a ticket that allows access to that checkpoint. Once Bessie has access to a checkpoint, she may return to it at any point in the future. She may travel between two checkpoints to which she has access, regardless of whether their labels differ by 1 or not.

For each of i[1,N]i\in [1,N], output the minimum total price required to purchase access to both checkpoints 11 and NN if Bessie initially has access to only checkpoint ii. If it is impossible to do so, print 1-1 instead.

입력

The first line contains NN and KK.

Each of the next KK lines contains four integers cic_i, pip_i, aia_i, and bib_i for each 1iK1\le i\le K.

출력

NN lines, one for each checkpoint.

예제 입력 1

7 6
4 1 2 3
4 10 5 6
2 100 7 7
6 1000 1 1
5 10000 1 4
6 100000 5 6

예제 출력 1

-1
-1
-1
1111
10100
110100
-1

점수

Test cases 1-7 satisfy N,K1000N,K\le 1000.Test cases 8-19 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.