CF1651E.Sum of Matchings

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's denote the size of the maximum matching in a graph GG as MM(G)\mathit{MM}(G).

You are given a bipartite graph. The vertices of the first part are numbered from 11 to nn, the vertices of the second part are numbered from n+1n+1 to 2n2n. Each vertex's degree is 22.

For a tuple of four integers (l,r,L,R)(l, r, L, R), where 1≤l≤r≤n1 \le l \le r \le n and n+1≤L≤R≤2nn+1 \le L \le R \le 2n, let's define G′(l,r,L,R)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][l, r] or in the segment [L,R][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)G'(l, r, L, R) from the original graph, you have to remove all vertices ii such that i∉[l,r]i \notin [l, r] and i∉[L,R]i \notin [L, R], and all edges incident to these vertices.

Calculate the sum of MM(G(l,r,L,R))\mathit{MM}(G(l, r, L, R)) over all tuples of integers (l,r,L,R)(l, r, L, R) having 1≤l≤r≤n1 \le l \le r \le n and n+1≤L≤R≤2nn+1 \le L \le R \le 2n.

我们用 MM(G)\mathit{MM}(G) 表示图 GG 中最大匹配的大小。

给定一个二分图:第一部分的顶点编号为 11 到 nn,第二部分的顶点编号为 n+1n+1 到 2n2n,且每个顶点的度数均为 22。

对于四元组 (l,r,L,R)(l, r, L, R),其中 1≤l≤r≤n1 \le l \le r \le n 且 n+1≤L≤R≤2nn+1 \le L \le R \le 2n,定义图 G′(l,r,L,R)G'(l, r, L, R) 如下:其顶点集为原图中所有属于区间 [l,r][l, r] 或区间 [L,R][L, R] 的顶点;其边集为原图中所有两个端点分别属于上述两个区间的边。换言之,为从原图得到 G′(l,r,L,R)G'(l, r, L, R),需删除所有满足 i∉[l,r]i \notin [l, r] 且 i∉[L,R]i \notin [L, R] 的顶点 ii,以及所有与这些顶点关联的边。

请计算对所有满足 1≤l≤r≤n1 \le l \le r \le n 和 n+1≤L≤R≤2nn+1 \le L \le R \le 2n 的整数四元组 (l,r,L,R)(l, r, L, R),MM(G′(l,r,L,R))\mathit{MM}(G'(l, r, L, R)) 的总和。

输入格式

The first line contains one integer nn (2≤n≤15002 \le n \le 1500) — the number of vertices in each part.

Then 2n2n lines follow, each denoting an edge of the graph. The ii-th line contains two integers xix_i and yiy_i (1≤xi≤n1 \le x_i \le n; n+1≤yi≤2nn + 1 \le y_i \le 2n) — the endpoints of the ii-th edge.

There are no multiple edges in the given graph, and each vertex has exactly two incident edges.

第一行包含一个整数 nn(2≤n≤15002 \le n \le 1500)—— 表示二分图每一部分的顶点数。

接下来是 2n2n 行,每行表示图中的一条边。第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi≤n1 \le x_i \le n;n+1≤yi≤2nn + 1 \le y_i \le 2n)—— 表示第 ii 条边的两个端点。

给定图中不存在重边,且每个顶点恰好关联两条边。

输出格式

Print one integer — the sum of MM(G(l,r,L,R))\mathit{MM}(G(l, r, L, R)) over all tuples of integers (l,r,L,R)(l, r, L, R) having 1≤l≤r≤n1 \le l \le r \le n and n+1≤L≤R≤2nn+1 \le L \le R \le 2n.

输出一个整数——对所有满足 1≤l≤r≤n1 \le l \le r \le n 和 n+1≤L≤R≤2nn+1 \le L \le R \le 2n 的整数四元组 (l,r,L,R)(l, r, L, R),求 MM(G(l,r,L,R))\mathit{MM}(G(l, r, L, R)) 的总和。

输入输出样例

  • 输入#1

    5
    4 6
    4 9
    2 6
    3 9
    1 8
    5 10
    2 7
    3 7
    1 10
    5 8

    输出#1

    314

输入解题思路,AI测评打分。不知道怎么写?

首页