A14907 | Sum of Matchings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let's denote the size of the maximum matching in a graph $G$ as $\mathit{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 \le l \le r \le n$ and $n+1 \le L \le R \le 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 \notin [l, r]$ and $i \notin [L, R]$ , and all edges incident to these vertices.
Calculate the sum of $\mathit{MM}(G(l, r, L, R))$ over all tuples of integers $(l, r, L, R)$ having $1 \le l \le r \le n$ and $n+1 \le L \le R \le 2n$ .
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 \le l \le r \le n$ and $n+1 \le L \le R \le 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 \notin [l, r]$ and $i \notin [L, R]$ , and all edges incident to these vertices.
Calculate the sum of $\mathit{MM}(G(l, r, L, R))$ over all tuples of integers $(l, r, L, R)$ having $1 \le l \le r \le n$ and $n+1 \le L \le R \le 2n$ .
输入格式
The first line contains one integer $n$ ( $2 \le n \le 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 $x_i$ and $y_i$ ( $1 \le x_i \le n$ ; $n + 1 \le y_i \le 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.
Then $2n$ lines follow, each denoting an edge of the graph. The $i$ -th line contains two integers $x_i$ and $y_i$ ( $1 \le x_i \le n$ ; $n + 1 \le y_i \le 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 $\mathit{MM}(G(l, r, L, R))$ over all tuples of integers $(l, r, L, R)$ having $1 \le l \le r \le n$ and $n+1 \le L \le R \le 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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted