Under construction

Still being built. Things may change

Interception

Time limit8sMemory limit512 MB

Summary
Place the fewest listening devices on the edges of a street-wide phone-line graph so that every given call route is covered.
Level

Hard8 of 10

Topics
Graph, Greedy, Tree, Implementation
Solved
No attempts yet

Problem

You are helping your local Neighborhood Surveillance Association set up a surveillance system on your street in order to identify the culprits behind some recent unfortunate dog doo incidents.

The system consists of listening devices placed on the tin-can phone lines of the street (the idea being that sooner or later the dog doo malefactors will slip up and discuss their dirty deeds over the phone). Each listening device is placed on one of the phone lines connecting the houses, and it intercepts all calls that are routed along that phone line.

The phone line network looks as follows. One side of the street has odd-numbered houses, and the other side has even-numbered houses. The numbers are lined up so that odd-numbered house ii is directly across the street from even-numbered house i+1i + 1. On both sides of the street, there are direct phone lines between adjacent pairs of houses. In addition, there are two direct phone lines connecting the two sides of the street. Each of these two phone lines connects a house with the house directly across from it.

Calls between two houses on the same side of the street are routed along the direct path between the two houses, without going to the other side of the street. For calls between two houses on opposite sides of the street, we know which of the two direct connections across the street the call uses. From previous ventures, we also know which people on the street are on speaking terms with each other. We would like to place listening devices so that we can intercept all phone calls. In other words, for every pair of people that are on speaking terms with each other, there must be a listening device on the route between their houses.

Listening devices are fairly expensive, and we burnt most of our budget on the barbecue last week. Your job is to find the minimum possible number of listening devices needed to do this.

Figure I.1: The phone line network in Sample Input 1. There are 14 houses, 7 on each side, and the two direct connections across the street connect house 3 with house 4, and house 9 with house 10. The people in houses 7 and 11 are on speaking terms, and calls between them are routed via house 9. The people in houses 5 and 6 are also on speaking terms, and calls between them are routed via houses 7, 9, 10, and 8. Sample Input 2 is similar, but there the calls between 5 and 6 are instead routed via the direct connection between houses 3 and 4.

Input

The first line of input contains four integers nn, mm, c1c_1, and c2c_2 (4≤n≤250 0004 \le n \le 250\,000, 1≤m≤500 0001 \le m \le 500\,000, 1≤c1<c2<n1 \le c_1 < c_2 < n). Here nn is even and is the number of houses on the street, mm is the number of pairs of people that are on speaking terms with each other, and c1c_1 and c2c_2 are odd, meaning that the two wires crossing the street go between houses c1c_1 and c1+1c_1 + 1, and between houses c2c_2 and c2+1c_2 + 1.

Then follow mm lines, each beginning with two distinct integers aa and bb between 1 and nn (inclusive), indicating that the person in house aa is on speaking terms with the person in house bb. If the two houses are on opposite sides of the street, they are followed by an integer c∈{c1,c2}c \in \{c_1, c_2\} indicating that calls between aa and bb are routed along the direct connection between houses cc and c+1c + 1. Each pair {a,b}\{a, b\} appears at most once in the input.

Output

Output one line with an integer ll, the smallest possible number of listening devices needed.

Examples2

  1. Example 1

    Input
    14 2 3 9
    7 11
    5 6 9
    
    Expected output
    1
    
  2. Example 2

    Input
    14 2 3 9
    7 11
    5 6 3
    
    Expected output
    2