题解——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 ...
随机推荐
- Vue系列之 => 组件中的data和methods
使用data <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- SlimScroll插件学习
SlimScroll插件学习 SlimScroll插件,是一个很好用的滚动条插件. 第一个实例程序: js代码: <script src="../slimScroll/jquery-3 ...
- 从网站上扒网页,保存为file文件格式
保存下来的页面总是有部分特效缺失,可是文件包里已经有好几个js文件了. 例如想保存易迅的搜索页面,条件筛选栏的按钮全部失效了,按钮-更多.多选等 都没有反应,搜索结果的鼠标悬浮显示完整信息也没有了. ...
- FTL 数字有逗号
Long i=100000000l; Map model=new Map(); model.put("t",i); 在freemarker中显示为100,000,000 想按原样输 ...
- vue-cli项目npm run build后,index.html无法在浏览器打开
- HashMap 和 ConcurrentHashMap比较
基础知识: 1. ConcurrentHashMap: (JDK1.7) segment数组,分段锁:segment 内部是 HashEnty数组,类似HashMap: 统计长度的方法,先不加锁统计两 ...
- tomcat2章1
package ex02.pyrmont; import java.io.File; public class Constants { public static final String WEB_R ...
- GUI颜色、字体设置对话框
%颜色设置对话框 uisetcolor %c 红色 c=uisetcolor %默认规定颜色 c=uisetcolor([ ]); %设置曲线颜色 h = plot([:]); c = uisetco ...
- Kali linux vim使用命令笔记
Kali Linux系统的vi编辑器/vim编辑器的使用和CentOS有很多不同.基本使用方法如下 1.vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mode).插入模式 ...
- SpringMVC MultiActionController 默认方法名解析器
MultiActionController默认方法名解析器是指在请求的地址中加入指定方法名称 MultiActionController类具有一个属性methodNameResolver,方法名解析器 ...