WC '18 Finals S3 - Screen Time

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 2.5s
Memory limit: 64M

Author:
Problem type
Woburn Challenge 2018-19 Finals Round - Senior Division

A trio of rival actors, numbered 13 from oldest to youngest, are set to make appearances in the cows' and monkeys' film. However, their contracts state that the oldest of them (actor 1) must receive more screen time than either one of the others! The Head Monkey may need to adjust her script to ensure that that's the case.

There are N (1N200000) possible equal-length scenes to include in the script, each of which involves exactly two of the three actors in question. The i-th scene features the two actors Ai and Bi (1Ai,Bi3,AiBi). The Head Monkey may select any non-empty subset of these N scenes to include (note that there are 2N1 such possible subsets).

Letting Si be the number of scenes featuring actor i, how many different subsets of scenes could the Head Monkey choose to include such that both S1>S2 and S1>S3 hold? As there may be many valid subsets, you only need to compute the number of them modulo 1000000007.

Subtasks

In test cases worth 24% of the points, N20.
In test cases worth another 18% of the points, N200.
In test cases worth another 18% of the points, N3000.

Input Specification

The first line of input consists of a single integer, N.
N lines follow, the i-th of which consists of two space-separated integers, Ai and Bi, for i=1N.

Output Specification

Output a single integer, the number of valid subsets of scenes (modulo 1000000007).

Sample Input 1

Copy
5
3 1
1 2
3 2
2 3
3 1

Sample Output 1

Copy
3

Sample Input 2

Copy
15
3 2
1 2
3 1
2 1
2 1
2 3
1 3
3 2
1 2
1 3
2 3
3 1
1 3
2 3
2 1

Sample Output 2

Copy
7266

Sample Explanation

In the first case, if the subset of scenes {1,2} is chosen, then S1=2 while S2=S3=1, making this a valid subset. Subsets {1,2,5} and {2,5} are also valid. Therefore, the answer is 3mod1000000007=3.


Comments

There are no comments at the moment.