Under construction

Still being built. Things may change

Security Badge

Time limit3sMemory limit512 MB

Summary
Given a directed graph whose edges each allow a range of badge IDs, count the badge IDs x for which room t is reachable from s.
Level

Medium7 of 10

Topics
Graph, BFS, Intervals, Implementation
Solved
No attempts yet

Problem

You are in charge of security for a large building with nn rooms and mm doors between the rooms. Rooms are numbered 1 to nn, and doors are numbered 1 to mm.

Door ii opens from room aia_i to room bib_i and not the other way around. Every door has a security code given as a range of integers [ci,di][c_i, d_i].

There are kk employees in the building. Each employee carries a security badge, and the badge IDs are distinct integers between 1 and kk. An employee whose badge ID is xx goes through door ii only when ci≤x≤dic_i \le x \le d_i.

Your boss wants a quick check of the building's security. Given ss and tt, how many employees can get from room ss to room tt?

Input

The first line contains three space separated integers nn, mm, and kk (2≤n≤1 0002 \le n \le 1\,000, 1≤m≤5 0001 \le m \le 5\,000, 1≤k≤1091 \le k \le 10^9).

The second line contains two space separated integers ss and tt (1≤s,t≤n1 \le s, t \le n, s≠ts \ne t).

Each of the next mm lines contains four space separated integers aia_i, bib_i, cic_i, and did_i describing door ii (1≤ai,bi≤n1 \le a_i, b_i \le n, 1≤ci≤di≤k1 \le c_i \le d_i \le k, ai≠bia_i \ne b_i).

For any two rooms aa and bb there is at most one door from aa to bb, but a door from aa to bb and a door from bb to aa may both exist.

Output

Print, on a single line, the number of employees who can reach room tt starting from room ss.

Examples2

  1. Example 1

    Input
    4 5 10
    3 2
    1 2 4 7
    3 1 1 6
    3 4 7 10
    2 4 3 5
    4 2 8 9
    
    Expected output
    5
    
  2. Example 2

    Input
    4 5 9
    1 4
    1 2 3 5
    1 3 6 7
    1 4 2 3
    2 4 4 6
    3 4 7 9
    
    Expected output
    5