CF1651E.Sum of Matchings
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's denote the size of the maximum matching in a graph G as MM(G) .
You are given a bipartite graph. The vertices of the first part are numbered from 1 to n , the vertices of the second part are numbered from n+1 to 2n . Each vertex's degree is 2 .
For a tuple of four integers (l,r,L,R) , where 1≤l≤r≤n and n+1≤L≤R≤2n , let's define G′(l,r,L,R) as the graph which consists of all vertices of the given graph that are included in the segment [l,r] or in the segment [L,R] , and all edges of the given graph such that each of their endpoints belongs to one of these segments. In other words, to obtain G′(l,r,L,R) from the original graph, you have to remove all vertices i such that i∈/[l,r] and i∈/[L,R] , and all edges incident to these vertices.
Calculate the sum of MM(G(l,r,L,R)) over all tuples of integers (l,r,L,R) having 1≤l≤r≤n and n+1≤L≤R≤2n .
输入格式
The first line contains one integer n ( 2≤n≤1500 ) — the number of vertices in each part.
Then 2n lines follow, each denoting an edge of the graph. The i -th line contains two integers xi and yi ( 1≤xi≤n ; n+1≤yi≤2n ) — the endpoints of the i -th edge.
There are no multiple edges in the given graph, and each vertex has exactly two incident edges.
输出格式
Print one integer — the sum of MM(G(l,r,L,R)) over all tuples of integers (l,r,L,R) having 1≤l≤r≤n and n+1≤L≤R≤2n .
输入输出样例
输入#1
5 4 6 4 9 2 6 3 9 1 8 5 10 2 7 3 7 1 10 5 8
输出#1
314