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 ...
随机推荐
- deepin安装mysql记录
本文转载自http://www.linuxidc.com/Linux/2016-07/133128.htm sudo apt-get install mysql-server apt-get isnt ...
- JavaFile、递归、字节流、字符流整理
File 1.1 File类的构造函数 当需要把内存中的数据存储到持久化设备上这个动作称为输出(写)Output操作. 当把持久设备上的数据读取到内存中的这个动作称为输入 ...
- 常用的消息队列中间件mq对比
原文地址:https://blog.csdn.net/qq_30764991/article/details/80239076 消息队列中间件是分布式系统中重要的组件,主要解决应用耦合,异步消息,流量 ...
- SSH框架之hibernate《二》
Hibernate第二天 一.hibernate的持久化类和对象标识符 1.1持久化类的编写规范 1.1.1什么是持久化类: ...
- C++自定义String字符串类,支持子串搜索
C++自定义String字符串类 实现了各种基本操作,包括重载+号实现String的拼接 findSubStr函数,也就是寻找目标串在String中的位置,用到了KMP字符串搜索算法. #includ ...
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- String总结
- 用agular2做文件上传功能杂记-遁地龙卷风
(-1)功能描述 写一个功能,前台发起执行请求,后台执行任务,前台可以获取执行的进度,并取得最后的执行状态. (0)angular2 $http文件上传 这里之所以不用angular-file-upl ...
- 🍓rem单位在Chrome中字体大小异常 🍓
这是一个很少出现,而一旦出现就让人头疼难当的bug.....网上资料比较少. 解决:https://oss.so/article/87 即为html标签设置-webkit-text-size-adju ...
- RT throttling分析【转】
转自:https://blog.csdn.net/u012728256/article/details/72639612 Linux上调度策略为SCHED_FIFO的实时进程是根据优先级抢占运行的.当 ...