题目链接

CF1037E. Trips

题解

每次删点后,对不满足要求的点拓扑

代码

#include<map>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#define rep(a,b,c) for(int a = b;a <= c;++ a)
#define gc getchar()
#define pc putchar
inline int read() { int x = 0,f = 1; char c = gc; while(c < '0' || c > '9') c = gc; while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc; return x * f;
}
void print(int x) { if(x < 0) { pc('-'); x = -x; } if(x >= 10) print(x / 10); pc(x % 10 + '0');
}
const int maxn = 5000007;
int n,m,k;
int d[maxn];
bool del[maxn];
using namespace std;
#define pr pair<int,int>
#define mmp make_pair
map<pr,int> mp;
struct node { int v,next;
} edge[maxn];
int head[maxn],num = 0;
inline void add_edge(int u,int v) { edge[++ num].v = v; edge[num].next = head[u];head[u] = num;
}
int ans;
int u[maxn],v[maxn];
int Ans[maxn];
queue<int>q;
void solve(int x) {if(d[x] >= k || del[x]) return; del[x] = 1; q.push(x); ans --; while(!q.empty()) { int U = q.front(); q.pop(); for(int i = head[U];i;i = edge[i].next) { int V = edge[i].v; if(del[V]) continue; if(mp.count(mmp(U,V)) == 0) d[V] --; if(d[V] < k) { del[V] = true;ans --; q.push(V);}} }
}
int main() { n = read(),m = read(); k = read();  rep(i,1,m) { u[i] = read(),v[i] = read(); add_edge(u[i],v[i]); add_edge(v[i],u[i]); d[v[i]] ++;  d[u[i]] ++; } ans = n; rep(i,1,n) solve(i); mp.clear(); for(int i = m;i >= 1;-- i) {    Ans[i] = ans; if(!del[u[i]]) d[v[i]] -- ; if(!del[v[i]]) d[u[i]] -- ; mp[pr(u[i],v[i])] = 1; mp[pr(v[i],u[i])] = 1; solve(u[i]); solve(v[i]); } rep(i,1,m)print(Ans[i]),pc('\n');
} /*
500 2 3
58 102
250 411
*/ 

转载于:https://www.cnblogs.com/sssy/p/9904312.html

CF1037E. Trips相关推荐

  1. CF1037E Trips

    题目链接:传送门 很好的思路 读完题目想一想 倒着建边会比较好处理 因为删边的处理比加边要容易 所以离线下来倒着搞就可以了 /*** @Date: 2019-04-14T10:03:39+08:00* ...

  2. [Manthan, Codefest 18][Codeforces 1037E. Trips]

    题目链接:1037E - Trips 题目大意:有n个人,m天,每天晚上都会有一次聚会,一个人会参加一场聚会当且仅当聚会里有至少k个人是他的朋友.每天早上都会有一对人成为好朋友,问每天晚上最多能有多少 ...

  3. LeetCode Trips and Users(关联、分组,聚合)

    给出trips和users表 CREATE TABLE `trips` (   `Id` int(11) DEFAULT NULL,   `Client_Id` int(11) DEFAULT NUL ...

  4. Codechef TRIPS Children Trips (分块、倍增)

    题目链接: https://www.codechef.com/problems/TRIPS 感觉CC有点毒瘤啊.. 题解: 首先有一个性质可能是因为太傻所以网上没人解释,然而我看了半天: 就是正序和倒 ...

  5. 一二三系列之CodeChef分块——Chef and Churu,Chef and Problems,Children Trips

    文章目录 Chef and Churu source solution code Chef and Problems source solution code Children Trips sourc ...

  6. [CodeChef Trips]Children Trips

    Children Trips 题解 关于这种跳跃的**题,当它PPP值很大时几次就可以跳到目标节点了,而较小时却会跳很久,所以我们很快就可以想到对询问分类处理. 对于P>nP>\sqrt{ ...

  7. Codeforces - Trips

    题目链接:Codeforces - Trips 加边不好想,所以我们直接反向删边. 每次删除一条边,那么对应两个点的度都减1,每次都把度小于k的删掉,剩下的点就是答案. 删点直接标记即可,删边在set ...

  8. Trips and Users

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

  9. [CC-TRIPS]Children Trips

    [CC-TRIPS]Children Trips 题目大意: \(n(n\le10^5)\)座城市构成一棵树,且树上的每条边的长度\(l_i\)满足\(1\le l_i\le 2\).\(m(m\le ...

最新文章

  1. 柳叶刀新文 | 利用统计模型与大数据探寻人口流动与新冠传播的潜在联系
  2. sybase数据库导出mysql_sybase导出数据库的表结构命令
  3. 4.1 matlab二维曲线绘图方法
  4. photo如何制作长图(外送搞笑毒故事)
  5. 小鹏汽车4月交付量5147台 同比增长285%
  6. 【渝粤教育】电大中专药剂学基础知识 (2)_1作业 题库
  7. 使用JavaScript分别实现4种样式的九九乘法表(1X1分别在左上、左下、右上、右下)...
  8. uni-app商城源码/公众号/小程序/APP多端适配
  9. 联想 计算机无线网络设置方法,联想笔记本无线网络开关,教您联想笔记本无线网络开关...
  10. gitee上贡献度不显示问题的设置
  11. 常见的几种最优化方法(梯度下降法、牛顿法、拟牛顿法、共轭梯度法等)
  12. python定向爬虫之淘宝商品比价
  13. [游戏安全] Unity3D游戏无意中的发现
  14. C# Parellel.For 和 Parallel.ForEach
  15. 【NDN IoT】Caching in Named Data Networking for the Wireless Internet of Things
  16. @Inherited
  17. 【NoteBook】刘润:新零售:低价高效的数据赋能之路
  18. wps如何修改已经存在的目录标题内容?
  19. C++ 第八节数据结构 第七节 ——二叉搜索树 AVL树 红黑树(底层原理图+模拟实现)
  20. 编译32/64位OpenCASCADE的详细步骤

热门文章

  1. 全国省市区Json文件 ,做省市区联动很轻松
  2. 魔兽世界怀旧服务器无限刷怪点,魔兽世界怀旧服法师A怪升级路线地点 法师刷怪速升60全攻略...
  3. 宝宝小暑吃什么,祛湿健脾,温补阳气
  4. python 正则表达函数_python笔记-正则表达式常用函数
  5. dns劫持 tplink_路由器dns被劫持有什么后果【图】
  6. 今天来个好玩儿的 “ 反射 ”
  7. 认识VF--Visual FoxPro 漫谈(轉)
  8. 【一键卸载mysql-5.7.38数据库+dos命令bat脚本】
  9. 奥运伙伴2008年活动
  10. 200604013个人日志(摘录一些厦门集美区教育局06年招人的信息)