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的更多相关文章
- cf1037E. Trips(图论 set)
题意 题目链接 Sol 倒着考虑!倒着考虑!倒着考虑! 显然,一个能成为答案的子图一定满足,其中任意节点的度数\(>= k\) 那么倒着维护就只用考虑删除操作,如果一个点不合法的话就把它删掉,然 ...
- CF1037E Trips (离线+图上构造)
题目大意:一共有n个人,每天早上会有两个人成为朋友,朋友关系不具有传递性,晚上,它们会组织旅游,如果一个人去旅游,那么他不少于$k$个朋友也要和他去旅游,求每天的最大旅游人数 一开始并没有想到反向建图 ...
- [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 ...
- 【Leetcode-Mysql】Trips and Users
思路不总结了,看过题目自己尝试过之后,看下方代码应该能理解的 SELECT Request_at AS DAY, round( sum( CASE WHEN STATUS = 'completed' ...
- CF#335 Intergalaxy Trips
Intergalaxy Trips time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- [SQL]LeetCode262.行程和用户 | Trips and Users
SQL架构 Create table If Not Exists Trips (Id )) Create table If Not Exists Users (Users_Id ), Role ENU ...
- [Manthan, Codefest 18][Codeforces 1037E. Trips]
题目链接:1037E - Trips 题目大意:有n个人,m天,每天晚上都会有一次聚会,一个人会参加一场聚会当且仅当聚会里有至少k个人是他的朋友.每天早上都会有一对人成为好朋友,问每天晚上最多能有多少 ...
- [CC-TRIPS]Children Trips
[CC-TRIPS]Children Trips 题目大意: \(n(n\le10^5)\)座城市构成一棵树,且树上的每条边的长度\(l_i\)满足\(1\le l_i\le 2\).\(m(m\le ...
随机推荐
- python之模块之shutil模块
shutil -- --High-level file operations 高级的文件操作模块. os模块提供了对目录或者文件的新建/删除/查看文件属性,还提供了对文件以及目录的路径操作.比如说: ...
- Java多线程_复习(更新中!!)
java多线程的常见例子 一.相关知识: Java多线程程序设计到的知识: (一)对同一个数量进行操作 (二)对同一个对象进行操作 (三)回调方法使用 (四)线程同步,死锁问题 (五)线程通信 等等 ...
- 剑指Offer_编程题_21
题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. class Solution { public: void push(int value) { st.push(val ...
- 更改Jenkins的workspace目录
系统管理→系统设置→主目录(的右边问号下面)→高级(是不是忽略了啊\(^o^)/~)→工作空间根目录 点开后面的问号可以看见3个参数(配置路径需要的): ${JENKINS_HOME} — Jenki ...
- Java中谈尾递归--尾递归和垃圾回收的比较
一.首先我们讲讲递归 1.递归的本质是,某个方法中调用了自身,本质还是调用了一个方法,只是这个方法正好是自身而已 2.递归因为是在自身中调用自身,所以会带来以下三个显著特点: 1.调用的是同一个 ...
- 51nod--1069 Nim 游戏(博弈论)
题目: 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N及每堆石子的数量 ...
- 克隆虚拟机+Linux互相登录+秘钥认证(四)
1.虚拟机右键管理_克隆 修改虚拟机名称后完成! 2.开机启动虚拟机 随时保存快照 3.开启两台虚拟机,进行互相登录切换!(W命令查看系统负载) 补充: IP登录: ssh IP: 例如:ssh 19 ...
- Java面试题复习笔记(框架)
1.什么是框架? 为解决一个开放性问题而设计的具有一定约束性的支撑结构,再次结构上可以根据具体问题扩展,安插更多的组成部分,从而更迅速和方便地构建完整解决问题的方案. 2.MVC模式? 用一种业务逻辑 ...
- 什么是内部类? Static Nested Class 和 Inner Class 的不同。
什么是内部类? Static Nested Class 和 Inner Class 的不同. 内部类就是在一个类的内部定义的类,内部类中不能定义静态成员(静态成员不是对象的特性,只是为了 ...
- 巧用Win+R
calc 启动计算器 charmap 启动字符映射表 chkdsk Chkdsk磁盘检查 cleanmgr 磁盘清理 clipbrd 剪贴板查看器 cmd CMD命令提示符 dvdplay DVD播放 ...