比赛的时候想到怎么做了 没调出来(感觉自己是个睿智)

给你N个点M条边,这M条边是一条一条加进去的 要求你求出加入每一条边时图中极大'K度'子图的大小

极大'K度'子图的意思是 要求出一个有尽量多的点的子图 该图中每个点的度数至少为K

因为他每加一条边只会影响到两个点的度数 所以很明显下一个极大'K度'子图是在上一个的基础上得来的

所以如果我们知道在最早哪一步加入边时 产生了极大'K度'子图的话 我们就可以对每条边进行判定得出答案

但是如果每一步都判是否有极大'K度'子图 肯定会超时 该题是离线询问 所以可以考虑倒着做

先把M条边全部加进去 再拓扑排序 每次POP出一个度数小于K的节点  在图中删掉他所连的边 直至队列为空

得出了ans[M] 我们倒着枚举处理每条边即可

 /*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
vector<int> tree[];
pair<int, int> edge[];
int ans[];
int du[];
queue<int> que;
bool vis[];
map<pair<int, int>, int> mp;
int main()
{
ios_base::sync_with_stdio();
cin.tie(); int n, m, k;
int u, v;
cin >> n >> m >> k;
for (int i = ; i <= m; i++)
{
cin >> u >> v;
edge[i].first = u, edge[i].second = v;
du[v]++, du[u]++;
tree[u].pb(v), tree[v].pb(u);
}
for (int i = ; i <= n; i++)
{
if (du[i] < k)
{
que.push(i);
vis[i] = true;
}
}
while (que.size())
{
int now = que.front();
que.pop();
for (auto v : tree[now])
{
if (mp[make_pair(now, v)])
{
continue;
}
du[v]--;
mp[make_pair(now, v)] = mp[make_pair(v, now)] = ;
if (du[v] < k && (!vis[v]))
{
vis[v] = true;
que.push(v);
}
}
}
for (int i = ; i <= n; i++)
{
if (!vis[i])
{
ans[m]++;
}
}
for (int i = m - ; i >= ; i--)
{
ans[i] = ans[i + ];
u = edge[i + ].first, v = edge[i + ].second;
if (mp[make_pair(u, v)])
{
continue;
}
du[u]--, du[v]--;
mp[make_pair(u, v)] = mp[make_pair(v, u)] = ;
if (du[u] < k && (!vis[u]))
{
vis[u] = true;
que.push(u);
ans[i]--;
}
if (du[v] < k && (!vis[v]))
{
vis[v] = true;
que.push(v);
ans[i]--;
}
while (que.size())
{
int now = que.front();
que.pop();
for (auto v : tree[now])
{
if (mp[make_pair(now, v)])
{
continue;
}
du[v]--;
mp[make_pair(now, v)] = mp[make_pair(v, now)] = ;
if (du[v] < k && (!vis[v]))
{
ans[i]--;
vis[v] = true;
que.push(v);
}
}
}
}
for (int i = ; i <= m; i++)
{
cout << ans[i] << endl;
}
return ;
}

//E.Trips

Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E.Trips的更多相关文章

  1. Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D,E

    D. Valid BFS? time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. 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 ...

  3. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E bfs + 离线处理

    https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k ...

  4. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C D

    C - Equalize #include<bits/stdc++.h> using namespace std; using namespace std; string a,b; int ...

  5. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  6. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)

    随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...

  7. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)

    是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...

  8. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)

    题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...

  9. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)

    就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...

随机推荐

  1. Python的Multiprocessing多进程实例

    最近在拜读RBG大神的faster-rcnn源码时发现他用了多进程去分阶段处理神经网络,原因如下: # ------------------------------------------------ ...

  2. Kubernetes中的PV和PVC

    K8S引入了一组叫作Persistent Volume Claim(PVC)和Persistent Volume(PV)的API对象,大大降低了用户声明和使用持久化Volume的门槛.在Pod的Vol ...

  3. C#编程 委托 Lambda表达式和事件

    委托 如果我们要把方法当做参数来传递的话,就要用到委托.简单来说委托是一个类型,这个类型可以赋值一个方法的引用. 声明委托 在C#中使用一个类分两个阶段,首选定义这个类,告诉编译器这个类由什么字段和方 ...

  4. 分片式图片服务器fastDFS安装过程

    1. 什么是FastDFS FastDFS 是用 c 语言编写的一款开源的分布式文件系统.FastDFS 为互联网量身定制, 充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标, ...

  5. 【Linux开发】linux设备驱动归纳总结(三):4.ioctl的实现

    linux设备驱动归纳总结(三):4.ioctl的实现 一.ioctl的简介: 虽然在文件操作结构体"struct file_operations"中有很多对应的设备操作函数,但是 ...

  6. C++学习笔记-多态的实现原理

    深入了解多态的实现原理,有助于提高对于多态的认识 多态基础 多态的实现效果 多态:同样的调用语句有多种不同的表现形态 多态实现的三个条件 有继承.有virtual重写.有父类指针(引用)指向子类对象 ...

  7. DataGridView中的ComboboxCell报了System.ArgumentException:DagaGridViewComboBoxCell值无效错误

    原因是初始化的时候给ComboboxCell绑定了一系列的值,但是真正赋值的时候却给了一个不在那一系列值范围中的值,所以就报了这个错 在开发的时候难免会因为数据的问题出现这个问题,为了不让系统崩掉,就 ...

  8. 笔记本通过命令配置wifi win7系统

    查看本子是否支持承载网络 在开始菜单>附件>命令提示符(右键点击:以管理员身份运行) 命令行中输入以下内容,找到[支持的承载网络]这一行,如果为"是"就OK了,表示支持 ...

  9. 【DP 好题】hihoCoder #1520 古老数字

    题目链接 这道题的要点是状态转移的顺序. 要从低位向高位进行状态转移. Implementation string s; cin >> s; reverse(all(s)); int x, ...

  10. Java 子类继承父类成员中的问题

    之前搞错了,变量没有“重写”一说,只有方法才能被“重写”.如果我们在子类中声明了一个和父类中一样的变量,那么实际的情况是,子类的内存堆中会有类型和名字都相同的两个变量. 现在考虑一种情况,如下所示,我 ...