题目链接

CF1037E. Trips

题解

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

代码

  1. #include<map>
  2. #include<queue>
  3. #include<vector>
  4. #include<cstdio>
  5. #include<algorithm>
  6. #define rep(a,b,c) for(int a = b;a <= c;++ a)
  7. #define gc getchar()
  8. #define pc putchar
  9. inline int read() {
  10. int x = 0,f = 1;
  11. char c = gc;
  12. while(c < '0' || c > '9') c = gc;
  13. while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
  14. return x * f;
  15. }
  16. void print(int x) {
  17. if(x < 0) {
  18. pc('-');
  19. x = -x;
  20. }
  21. if(x >= 10) print(x / 10);
  22. pc(x % 10 + '0');
  23. }
  24. const int maxn = 5000007;
  25. int n,m,k;
  26. int d[maxn];
  27. bool del[maxn];
  28. using namespace std;
  29. #define pr pair<int,int>
  30. #define mmp make_pair
  31. map<pr,int> mp;
  32. struct node {
  33. int v,next;
  34. } edge[maxn];
  35. int head[maxn],num = 0;
  36. inline void add_edge(int u,int v) {
  37. edge[++ num].v = v; edge[num].next = head[u];head[u] = num;
  38. }
  39. int ans;
  40. int u[maxn],v[maxn];
  41. int Ans[maxn];
  42. queue<int>q;
  43. void solve(int x) {
  44. if(d[x] >= k || del[x]) return;
  45. del[x] = 1;
  46. q.push(x);
  47. ans --;
  48. while(!q.empty()) {
  49. int U = q.front();
  50. q.pop();
  51. for(int i = head[U];i;i = edge[i].next) {
  52. int V = edge[i].v;
  53. if(del[V]) continue;
  54. if(mp.count(mmp(U,V)) == 0) d[V] --;
  55. if(d[V] < k) { del[V] = true;ans --; q.push(V);}
  56. }
  57. }
  58. }
  59. int main() {
  60. n = read(),m = read(); k = read();
  61. rep(i,1,m) {
  62. u[i] = read(),v[i] = read();
  63. add_edge(u[i],v[i]);
  64. add_edge(v[i],u[i]);
  65. d[v[i]] ++;
  66. d[u[i]] ++;
  67. }
  68. ans = n;
  69. rep(i,1,n)
  70. solve(i);
  71. mp.clear();
  72. for(int i = m;i >= 1;-- i) {
  73. Ans[i] = ans;
  74. if(!del[u[i]]) d[v[i]] -- ;
  75. if(!del[v[i]]) d[u[i]] -- ;
  76. mp[pr(u[i],v[i])] = 1;
  77. mp[pr(v[i],u[i])] = 1;
  78. solve(u[i]);
  79. solve(v[i]);
  80. }
  81. rep(i,1,m)print(Ans[i]),pc('\n');
  82. }
  83. /*
  84. 500 2 3
  85. 58 102
  86. 250 411
  87. */

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. HTML编辑器KindEditor

    KindEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框(textarea)替换为可视化的富文本 ...

  2. python之OpenCv(五)---抓取摄像头视频图像

    OpenCV 可以通过 头videoCapture()方法打开摄像 摄像头变量 = cv2.VideoCapture(n)   n为整数,内置摄像头为0,若有其他摄像头则依次为1,2,3,4,... ...

  3. MAC OS进阶必看——这10个技巧让你秒变MAC达人

    文章内容及图片来源于:什么值得买,如果涉及版权问题,请联系作者删除 文章收录于:风云社区(提供上千款各类mac软件的下载) 使用mac系统也有好几个年头,出色的办公效率以及越来越广的兼容性让mac成为 ...

  4. 第十一节: EF的三种模式(一) 之 DBFirst模式(SQLServer和MySQL两套方案)

    一. 简介 EF连接数据库有三种模式,分别是DBFirst.ModelFirst.CodeFirst,分别适用于不同的开发场景. 该章节,将主要介绍EF的DBFirst连接SQLServer数据库和M ...

  5. HP Z620 Windows 7 系统安装(含磁盘阵列)

    由于HP Z620 做了Raid 5磁盘阵列,导致安装系统时,系统加载不了磁盘的驱动,无法将系统安装到硬盘上,正确的方法是:下载SATA驱动,在需要加载驱动的地方,利用另一个U盘,“浏览”解压好的驱动 ...

  6. [再寄小读者之数学篇](2014-05-23 $\ln x-ax=0$ 有两个根时的估计)

    已知函数 $f(x)=\ln x-ax$, 其中 $a$ 为常数. 如果 $f(x)$ 有两个零点 $x_1,x_2$. 试证: $x_1x_2>e^2$. 证明: 由 $$\bex \ln x ...

  7. java8 list和map的forEach

    list forEach示例 public class HelloWorld { public static void main(String[] args) { List<User> l ...

  8. Factorized TDNN(因子分解TDNN,TDNN-F)

    论文 Povey, D., Cheng, G., Wang, Y., Li, K., Xu, H., Yarmohamadi, M., & Khudanpur, S. (2018). Semi ...

  9. CDH5.16.1启动报错:Invalid value set for db.setupType, the valid values are EMBEDDED or EXTERNAL

    1 自己的配置文件已经添加了配置,但是还是报错,由于是自建数据库 com.cloudera.cmf.db.setupType=EXTERNAL 2,索性注释掉这个参数,启动就ok了

  10. Java的三大特性

    一.封装性 含义:对外不可见,保护属性和方法不被外部多看见 实现:通过关键字private声明,用get.set方法为外部访问. 引用的传递: static关键字:修饰属性(全局属性):修饰方法(直接 ...