Codeforces - 1198C - Matching vs Independent Set - 贪心
https://codeforces.com/contest/1198/problem/C
要选取一个大小大于等于n的匹配或者选取一个大小大于等于n的独立集。
考虑不断加入匹配集,最终加入了x条边。
那么剩下的点之间是没有边可以加的,否则匹配数还会增加,也就是剩下的点要么没有边可以连,要么这些边去往的点都在匹配里面。
考虑x>=n,之间输出。
否则x<n,则剩下的点至少有3n-2x个,这些全部选上也>=n,连匹配里面的点都不需要动(因为匹配里面的点可能会和匹配外的点有边连通)。
其实看见有3*n个点应该反应到是要为什么这样搞的。
#include<bits/stdc++.h>
using namespace std;
bool vis[300005];
int eid[500005], etop;
void init(int n, int m) {
memset(vis, 0, sizeof(vis[0]) * (3*n + 1));
etop = 0;
}
void update(int i) {
int u, v;
scanf("%d%d", &u, &v);
if(vis[u] || vis[v])
return;
else {
vis[u] = vis[v] = 1;
eid[++etop] = i;
}
}
void Matching(int n) {
puts("Matching");
for(int i = 1; i <= n; ++i) {
printf("%d%c", eid[i], " \n"[i == n]);
}
}
void IndSet(int n) {
puts("IndSet");
int cnt = 0;
for(int i = 1; i <= 3 * n; ++i) {
if(!vis[i]) {
++cnt;
printf("%d%c", i, " \n"[cnt == n]);
if(cnt == n)
return;
}
}
}
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
int T;
scanf("%d", &T);
int n, m;
while(T--) {
scanf("%d%d", &n, &m);
init(n, m);
for(int i = 1; i <= m; ++i) {
update(i);
}
if(etop >= n) {
Matching(n);
} else {
IndSet(n);
}
}
}
以前没怎么接触过什么匹配、独立集,不会做才正常。
Codeforces - 1198C - Matching vs Independent Set - 贪心的更多相关文章
- CodeForces 1198C 1199E Matching vs Independent Set
Time limit 1000 ms Memory limit 262144 kB 这题是一场cf里,div1的第三题,div2的第5题 中文题意 给一张无向图,没说连通性,要你选出一个大小为n的匹配 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces 437D The Child and Zoo(贪心+并查集)
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...
- CodeForces - 777B Game of Credit Cards 贪心
题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
随机推荐
- Git版本控制工具初识
Git使用教程 0 Git下载安装 下载网址:https://www.git-scm.com/download/ 安装时,一路next就可以了,如果遇到下载很慢时,可以选择换个浏览器试试,实在不行就找 ...
- compile and link C/CPP programs on Mac
ref: https://stackoverflow.com/questions/29987716/cannot-use-gsl-library-on-macos-ld-symbols-not-fou ...
- Postman—cookie
postman中可以直接添加cookie.查看响应中的cookie: 什么是cookie HTTP协议本身是无状态的.什么是无状态呢,即服务器无法判断用户身份.Cookie实际上是一小段的文本信息(k ...
- tapmode="hover"属性
.hover{ opacity: .; } <span tapmode="hover" onclick="fnOpen()">open</sp ...
- Sonys TRC save data plolicy
帖子地址:https://forums.unrealengine.com/showthread.php?130820-Sonys-TRC-save-data-plolicy we had severa ...
- codeforces D Salary Changing
题意:给你n个人,和s块钱,每个人都有一个工资区间,你给所有人都发工资.然后要他们工资的中位数最大. 思路:二分找那个值.那个值要满足至少有n/2+1个工资区间内. #include<cstdi ...
- Mybatis,模糊查询语句,以及传参数的正确写法
不多说直接上代码! 接口: public interface CommodityMapper { int deleteByPrimaryKey(Integer productId); int inse ...
- 接上SQL SERVER的锁机制(一)——概述(锁的种类与范围)
二.完整的锁兼容性矩阵(见下图) 对上图的是代码说明:见下图. 三.下表列出了数据库引擎可以锁定的资源. 名称 资源 缩写 编码 呈现锁定时,描述该资源的方式 说明 数据行 RID RID 9 文件编 ...
- ORACLE 根据sql_id查询绑定变量的传入值
当前查询: select b.NAME, b.POSITION, b.DATATYPE_STRING, b.VALUE_STRING, b.LAST_CAPTURED from v$sql_bind_ ...
- 查看在linux中下载的图片
1.安装 yum install lrzsz -y 2.找到文件所在的位置选中之后 3.点击那个蓝色的框框里面有一个 用ZMODEM下载 4.选择要保存的位置就可以查看了