题目链接

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
*/

CF1037E. Trips的更多相关文章

  1. cf1037E. Trips(图论 set)

    题意 题目链接 Sol 倒着考虑!倒着考虑!倒着考虑! 显然,一个能成为答案的子图一定满足,其中任意节点的度数\(>= k\) 那么倒着维护就只用考虑删除操作,如果一个点不合法的话就把它删掉,然 ...

  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-Mysql】Trips and Users

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

  5. CF#335 Intergalaxy Trips

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

  6. leetcode——262. Trips and Users

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

  7. [SQL]LeetCode262.行程和用户 | Trips and Users

    SQL架构 Create table If Not Exists Trips (Id )) Create table If Not Exists Users (Users_Id ), Role ENU ...

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

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

  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. 分布式监控系统开发【day37】:监控客户端开发(五)

    一.目录结构 二.模块方法调用关系总图 三.入口文件main 1.解决了说明问题 1.客户端就干了一件事情,干什么事情 收集数据汇报给服务端? 但是我这个客户端是插件形式2.首先必须要传一个参数,st ...

  2. openJDK之如何下载各个版本的openJDK源码

    如果我们需要阅读openJDK的源码,那么需要下载,那么该去哪下载呢? 现在JDK已经发展到版本10了,11已经处于计划中,如果需要特定版本的openJDK,它们的下载链接在哪呢? 1.openJDK ...

  3. Javaweb学习笔记——(二十八)——————Servlet3.0、动态代理、类加载器

    web最后一天:完了. Servlet3.0          一.要求         1.MyEclipse10.0或以上版本         2.发布到Tomcat7.0或以上版本 二.步骤   ...

  4. 多人聊天室(Java)

    第1部分 TCP和UDP TCP:是一种可靠地传输协议,是把消息按一个个小包传递并确认消息接收成功和正确才发送下一个包,速度相对于UDP慢,但是信息准确安全:常用于一般不要求速度和需要准确发送消息的场 ...

  5. 【js课设】电子画板01

    这学期web开发课的课设选了电子画板课题.(人家本来想做富文本编辑器的嘛然鹅老师在第二版里把这题删掉了。゚ヽ(゚´Д`)ノ゚。) 主要考虑的有[界面美观][画笔类型][画布分层]这三个点了. [界面美 ...

  6. TCP/IP教程

    一.TCP/IP 简介 TCP/IP 是用于因特网的通信协议. 通信协议是对计算机必须遵守的规则的描述,只有遵守这些规则,计算机之间才能进行通信. 什么是 TCP/IP? TCP/IP 是供已连接因特 ...

  7. 练习:javascript-setInterval动画运动平移,定时器动画练习

    常见问题:定时器加速问题,每次点击会启动一个定时器,解决先清除定时器 <!DOCTYPE html> <html lang="en"> <head&g ...

  8. tcp协议的简单理解

    tpc协议属于传输层协议,本篇主要介绍下几个概念,以及握手和挥手的过程. 1.tcp的几个概念 位码:即tcp标志位,有6种提示 SYN:synchronus,表示建立联机. ACK:acknowle ...

  9. 集成方法 Boosting原理

    1.Boosting方法思路 Boosting方法通过将一系列的基本分类器组合,生成更好的强学习器 基本分类器是通过迭代生成的,每一轮的迭代,会使误分类点的权重增大 Boosting方法常用的算法是A ...

  10. [转] fastText

    mark- from : https://www.jiqizhixin.com/articles/2018-06-05-3 fastText的起源 fastText是FAIR(Facebook AIR ...