303477: CF673B. Problems for Round

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Problems for Round

题意翻译

$n$ 个问题,$m$ 对题目相似,给出 $m$ 对相似的题的编号; $n$ 个问题的难度值就为他们的编号,现在要将这 $n$ 个问题按要求放到两个题库里(div1,div2) 要求:div1中的题目难度要比div2中的每个题的难度都大,相似的题不能放到同一个题库中。 现在问有几种放法。 现在问有几种放法。

题目描述

There are $ n $ problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are $ m $ pairs of similar problems. Authors want to split problems between two division according to the following rules: - Problemset of each division should be non-empty. - Each problem should be used in exactly one division (yes, it is unusual requirement). - Each problem used in division 1 should be harder than any problem used in division 2. - If two problems are similar, they should be used in different divisions. Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other. Note, that the relation of similarity is not transitive. That is, if problem $ i $ is similar to problem $ j $ and problem $ j $ is similar to problem $ k $ , it doesn't follow that $ i $ is similar to $ k $ .

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ m $ ( $ 2<=n<=100000 $ , $ 0<=m<=100000 $ ) — the number of problems prepared for the round and the number of pairs of similar problems, respectively. Each of the following $ m $ lines contains a pair of similar problems $ u_{i} $ and $ v_{i} $ ( $ 1<=u_{i},v_{i}<=n,u_{i}≠v_{i} $ ). It's guaranteed, that no pair of problems meets twice in the input.

输出格式


Print one integer — the number of ways to split problems in two divisions.

输入输出样例

输入样例 #1

5 2
1 4
5 2

输出样例 #1

2

输入样例 #2

3 3
1 2
2 3
1 3

输出样例 #2

0

输入样例 #3

3 2
3 1
3 2

输出样例 #3

1

说明

In the first sample, problems $ 1 $ and $ 2 $ should be used in division 2, while problems $ 4 $ and $ 5 $ in division 1. Problem $ 3 $ may be used either in division 1 or in division 2. In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules. Third sample reminds you that the similarity relation is not transitive. Problem $ 3 $ is similar to both $ 1 $ and $ 2 $ , but $ 1 $ is not similar to $ 2 $ , so they may be used together.

Input

题意翻译

$n$ 个问题,$m$ 对题目相似,给出 $m$ 对相似的题的编号; $n$ 个问题的难度值就为他们的编号,现在要将这 $n$ 个问题按要求放到两个题库里(div1,div2) 要求:div1中的题目难度要比div2中的每个题的难度都大,相似的题不能放到同一个题库中。 现在问有几种放法。 现在问有几种放法。

加入题单

上一题 下一题 算法标签: