题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)
还是dfs?
好像自己写的有锅
过不去
看了题解修改了才过qwq
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <set>
using namespace std;
int u[],v[],n,m,k,ans;
bool isdel[],vis[];
set<int> sons[];
stack<int> S;
void dfs(int u){
if(sons[u].size()>=k)
return;
if(vis[u])
return;
vis[u]=true;
ans--;
for(auto i=sons[u].begin();i!=sons[u].end();i++){
sons[*i].erase(u);
dfs(*i);
}
sons[u].clear();
}
int main(){
scanf("%d %d %d",&n,&m,&k);
for(int i=;i<=m;i++){
scanf("%d %d",&u[i],&v[i]);
sons[u[i]].insert(v[i]);
sons[v[i]].insert(u[i]);
}
ans=n;
for(int i=;i<=n;i++)
dfs(i);
if(ans>=k){
S.push(ans);
}
else
S.push();
for(int i=m;i>=;i--){
sons[u[i]].erase(v[i]);
sons[v[i]].erase(u[i]);
dfs(u[i]);
dfs(v[i]);
if(ans>=k){
S.push(ans);
}
else
S.push();
}
while (!S.empty()) {
printf("%d\n",S.top());
S.pop();
}
return ;
}
题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)的更多相关文章
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)
随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)
题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)
就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 多重背包的二进制优化. 就是将数量x分成接近log2x份 然后这log2x份能组合成1..x内的所有数字. 从而将多重背包转化成01 ...
- Manthan, Codefest 18 (rated, Div. 1 + Div. 2) F 单调栈 + 贡献 + 计数
https://codeforces.com/contest/1037/problem/F 题意 function z(array a, integer k): if length(a) < k ...
- Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E bfs + 离线处理
https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k ...
随机推荐
- keras如何求分类问题中的准确率和召回率
https://www.zhihu.com/question/53294625 由于要用keras做一个多分类的问题,评价标准采用precision,recall,和f1_score:但是keras中 ...
- win10 Xshell5连ubuntu服务器
相当于ubuntu做服务器,win10远程访问,同一局域网下,完全参考度娘 教你怎么使用xshell远程连接linux服务器 ubuntu系统ifconfig -a查看ip地址,添加到主机那里,连接时 ...
- Spring cglib 初始化 ExceptionInInitializerError,new Enhancer() 异常
解决办法:更换 spring-cglib-repack-*.*.jar 包 java.lang.ExceptionInInitializerError at org.springframework.a ...
- win10 在任务栏添加 desktop 快捷图标
http://www.xitongcheng.com/jiaocheng/win10_article_11980.html [Shell] Command= IconFile=explorer.exe ...
- importlib
Python提供了importlib包作为标准库的一部分.目的就是提供Python中import语句的实现(以及__import__函数).另外,importlib允许程序员创建他们自定义的对象,可用 ...
- 【JavaScript 6连载】三、构造函数
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- vue-router基本使用
路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮 => home 内容, ...
- VI编辑器常用命令
Linux下的文本编辑器有很多种,vi 是最常用的,也是各版本Linux的标配.注意,vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能. ...
- amoeba读写分离
第一单元 高性能mysql读写分离的实现 5.1 mysql读写分离 5.1.1 mysql读写分离概述 5.1.2 mysql读写分离原理 5.2 mysql读写分离配置 ...
- 报文、http、https的理解
一.何为报文? 报文是网络中交换与传输的数据单位,即站点一次性要发送的数据块.报文包含了将要发送的完整的数据信息,其长短不一致,长度不限且可变. 二.报文的作用 报文多是多个系统之间需 ...