题意

题目链接

Sol

倒着考虑!倒着考虑!倒着考虑!

显然,一个能成为答案的子图一定满足,其中任意节点的度数\(>= k\)

那么倒着维护就只用考虑删除操作,如果一个点不合法的话就把它删掉,然后考虑与他相邻的点

如果不合法就继续删

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
const int MAXN = 2e5 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, K, vis[MAXN], inder[MAXN], Ans, ans[MAXN], vis2[MAXN];
Pair E[MAXN];
set<int> s[MAXN];
void delet(int x) {
if(vis[x]) return ;
vis[x] = 1; Ans--;
for(set<int>::iterator it = s[x].begin(); it != s[x].end(); it++) {
int to = *it; //s[x].erase(*it);
inder[to]--;
if(inder[to] < K) delet(to);
}
}
int main() {
Ans = N = read(); M = read(); K = read();
for(int i = 1; i <= M; i++) {
int x = read(), y = read();
s[x].insert(y); s[y].insert(x); inder[x]++; inder[y]++;
E[i] = MP(x, y);
}
for(int i = 1; i <= N; i++) if(inder[i] < K) delet(i);
for(int i = M; i >= 1; i--) {
ans[i] = Ans;
if(vis[E[i].fi] || vis[E[i].se]) continue;
inder[E[i].fi]--; inder[E[i].se]--;
s[E[i].fi].erase(E[i].se); s[E[i].se].erase(E[i].fi);
if(inder[E[i].fi] < K) delet(E[i].fi);
if(inder[E[i].se] < K) delet(E[i].se);
}
for(int i = 1; i <= M; i++) printf("%d\n", ans[i]);
return 0;
}

cf1037E. Trips(图论 set)的更多相关文章

  1. CF1037E. Trips

    题目链接 CF1037E. Trips 题解 每次删点后,对不满足要求的点拓扑 代码 #include<map> #include<queue> #include<vec ...

  2. CF1037E Trips (离线+图上构造)

    题目大意:一共有n个人,每天早上会有两个人成为朋友,朋友关系不具有传递性,晚上,它们会组织旅游,如果一个人去旅游,那么他不少于$k$个朋友也要和他去旅游,求每天的最大旅游人数 一开始并没有想到反向建图 ...

  3. [LeetCode] Trips and Users 旅行和用户

    The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are b ...

  4. [leetcode] 题型整理之图论

    图论的常见题目有两类,一类是求两点间最短距离,另一类是拓扑排序,两种写起来都很烦. 求最短路径: 127. Word Ladder Given two words (beginWord and end ...

  5. 【Leetcode-Mysql】Trips and Users

    思路不总结了,看过题目自己尝试过之后,看下方代码应该能理解的 SELECT Request_at AS DAY, round( sum( CASE WHEN STATUS = 'completed' ...

  6. 并查集(图论) LA 3644 X-Plosives

    题目传送门 题意:训练指南P191 分析:本题特殊,n个物品,n种元素则会爆炸,可以转移到图论里的n个点,连一条边表示u,v元素放在一起,如果不出现环,一定是n点,n-1条边,所以如果两个元素在同一个 ...

  7. CF#335 Intergalaxy Trips

     Intergalaxy Trips time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. NOIp 2014 #2 联合权值 Label:图论 !!!未AC

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  9. HDU 5521 [图论][最短路][建图灵感]

    /* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...

随机推荐

  1. 解决You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    pip install ...出现问题 直接输入python - pip install --upgrade pip就可以了

  2. springmvc.xml配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. 06. 用css实现三角形

    用css实现三角形   <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  4. angular5给懒加载模块添加loading

    在根组件的构造函数中直接执行: this.router.events.subscribe(event=>{ if(event instanceof RouteConfigLoadEnd) { t ...

  5. 3. Javascript学习笔记——变量、内存、作用域

    3. 变量.内存.作用域 3.1 基本类型和引用类型的值 ECMAScript 变量可能包含两种不同数据类型的值:基本类型值[Undefined.Null.Boolean.Number 和 Strin ...

  6. ImportError: No module named 'tkinter'

    环境说明: windows7.vscode1.33.1.python3.7.0. 解决方案: 通过安装程序单独卸载“tcl/tk and IDLE”------重新安装“tcl/tk and IDLE ...

  7. php session的简单使用

    创建session: session_start(); $_SESSION['name'] = $value; 获取session: session_start(); echo $_SESSION[' ...

  8. mysql编码不统一形成的错误

    错误提示:[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) ...

  9. 《大数据日知录》读书笔记-ch11大规模批处理系统

    MapReduce: 计算模型: 实例1:单词统计 实例2:链接反转 实例3:页面点击统计 系统架构: 在Map阶段还可以执行可选的Combiner操作,类似于Reduce,但是在Mapper sid ...

  10. 关于null的操作

    空值 空值一般用NULL表示 一般表示未知的.不确定的值,也不是空格 一般运算符与其进行运算时,都会为空 空不与任何值相等 表示某个列为空用:IS NULL  不能使用COMM=NULL这种形式 某个 ...