CF1037E Trips
题目链接:传送门
很好的思路
读完题目想一想
倒着建边会比较好处理
因为删边的处理比加边要容易
所以离线下来倒着搞就可以了
/*** @Date: 2019-04-14T10:03:39+08:00* @Last modified time: 2019-04-14T10:03:39+08:00*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define A 1000010
#define B 2010using namespace std;
typedef long long ll;
struct node {int next, to;
}e[A];
int head[A], num;
void add(int fr, int to) {e[++num].next = head[fr];e[num].to = to;head[fr] = num;
}
int ans, n, m, k, del[A], in[A], a[A], b[A], out[A];
map<pair<int, int>, bool> mm;
void work(int x) {queue<int> q; q.push(x);if (in[x] >= k or del[x]) return;del[x] = 1; ans--;while (!q.empty()) { //踢出能遍历到的所有不符合条件的点int fr = q.front(); q.pop();for (int i = head[fr]; i; i = e[i].next) {int ca = e[i].to;if (del[ca]) continue;if (!mm[make_pair(fr, ca)]) in[ca]--;if (in[ca] < k) {ans--; q.push(ca); del[ca] = 1;}}}
}int main(int argc, char const *argv[]) {cin >> n >> m >> k; ans = n;for (int i = 1; i <= m; i++) {cin >> a[i] >> b[i];add(a[i], b[i]); add(b[i], a[i]);in[a[i]]++; in[b[i]]++;}for (int i = 1; i <= n; i++) work(i);for (int i = m; i >= 1; i--) {out[i] = ans;if (!del[a[i]]) in[b[i]]--;if (!del[b[i]]) in[a[i]]--;mm[make_pair(a[i], b[i])] = mm[make_pair(b[i], a[i])] = 1;work(a[i]); work(b[i]);}for (int i = 1; i <= m; i++) cout << out[i] << endl;
}
CF1037E Trips相关推荐
- CF1037E. Trips
题目链接 CF1037E. Trips 题解 每次删点后,对不满足要求的点拓扑 代码 #include<map> #include<queue> #include<vec ...
- [Manthan, Codefest 18][Codeforces 1037E. Trips]
题目链接:1037E - Trips 题目大意:有n个人,m天,每天晚上都会有一次聚会,一个人会参加一场聚会当且仅当聚会里有至少k个人是他的朋友.每天早上都会有一对人成为好朋友,问每天晚上最多能有多少 ...
- LeetCode Trips and Users(关联、分组,聚合)
给出trips和users表 CREATE TABLE `trips` ( `Id` int(11) DEFAULT NULL, `Client_Id` int(11) DEFAULT NUL ...
- Codechef TRIPS Children Trips (分块、倍增)
题目链接: https://www.codechef.com/problems/TRIPS 感觉CC有点毒瘤啊.. 题解: 首先有一个性质可能是因为太傻所以网上没人解释,然而我看了半天: 就是正序和倒 ...
- 一二三系列之CodeChef分块——Chef and Churu,Chef and Problems,Children Trips
文章目录 Chef and Churu source solution code Chef and Problems source solution code Children Trips sourc ...
- [CodeChef Trips]Children Trips
Children Trips 题解 关于这种跳跃的**题,当它PPP值很大时几次就可以跳到目标节点了,而较小时却会跳很久,所以我们很快就可以想到对询问分类处理. 对于P>nP>\sqrt{ ...
- Codeforces - Trips
题目链接:Codeforces - Trips 加边不好想,所以我们直接反向删边. 每次删除一条边,那么对应两个点的度都减1,每次都把度小于k的删掉,剩下的点就是答案. 删点直接标记即可,删边在set ...
- Trips and Users
Trips and Users The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and ...
- [CC-TRIPS]Children Trips
[CC-TRIPS]Children Trips 题目大意: \(n(n\le10^5)\)座城市构成一棵树,且树上的每条边的长度\(l_i\)满足\(1\le l_i\le 2\).\(m(m\le ...
最新文章
- (第一次)NODEJS学习笔记
- 【收藏】maven跳过单元测试-maven.test.skip和skipTests的区别
- 计算机科技手抄报内容,科技手抄报内容云计算文字稿
- Windows Update Error: 80244019
- php 转义取消,php如何取消转义
- python多目标跟踪卡尔曼滤波_卡尔曼多目标跟踪的例子?
- STM32CubeMX软件工程描述_USART配置过程
- 中小企业信息管理 巧用E-Cell
- Activity的Launch mode详解 singleTask正解
- phpstorm内网远程debug
- 编译内核_Linux内核编译(自己实现的网卡上面测试c1000k案例)
- UCGUI的消息处理
- 计算机控制实验室装置,自控/计控原理实验箱 实验仪 实验装置 教学实训设备...
- screentogif能录制声音吗_一款免费且强大的gif动画录制工具,再也不愁录动画!...
- Texstduio+Miktex遇到ntx-Italic-tlf-t1 could not be created问题
- 心情整天都在郁闷浮云往事如云烟,撕心裂肺:伤感心情日志
- 自己写的vue图片上传插件(假装是插件)
- 明翰经验系列之管理篇V1.1(持续更新)
- 前Vertu设计师推出Android版iBeacon,无需专有硬件,没话费的旧手机都能做基站
- Python将图片转换为字符画