题意:

思路:这是一道论文题 https://link.springer.com/content/pdf/10.1007/BFb0066192.pdf

From http://www.cnblogs.com/zhouzhendong/p/CF1019C.html

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<string>
  4. #include<cmath>
  5. #include<iostream>
  6. #include<algorithm>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<vector>
  11. #include<bitset>
  12. using namespace std;
  13. typedef long long ll;
  14. typedef unsigned int uint;
  15. typedef unsigned long long ull;
  16. typedef pair<int,int> PII;
  17. typedef vector<int> VI;
  18. #define fi first
  19. #define se second
  20. #define MP make_pair
  21. #define N 1100000
  22. #define M 51
  23. #define MOD 1000000007
  24. #define eps 1e-8
  25. #define pi acos(-1)
  26. #define oo 3e14
  27.  
  28. vector<int> c[N];
  29. int a[N],b[N],q[N];
  30.  
  31. int main()
  32. {
  33. int n,m;
  34. scanf("%d%d",&n,&m);
  35. for(int i=;i<=n;i++) c[i].clear();
  36. for(int i=;i<=m;i++)
  37. {
  38. int x,y;
  39. scanf("%d%d",&x,&y);
  40. c[x].push_back(y);
  41. }
  42. for(int i=;i<=n;i++)
  43. if(!a[i])
  44. {
  45. for(int j=;j<=(int)c[i].size()-;j++) a[c[i][j]]=;
  46. a[i]=b[i]=;
  47. }
  48. for(int i=n;i>=;i--)
  49. if(b[i])
  50. {
  51. for(int j=;j<=(int)c[i].size()-;j++) b[c[i][j]]=;
  52. }
  53. int ans=;
  54. for(int i=;i<=n;i++)
  55. if(b[i]) q[++ans]=i;
  56. printf("%d\n",ans);
  57. for(int i=;i<=ans-;i++) printf("%d ",q[i]);
  58. printf("%d\n",q[ans]);
  59. return ;
  60. }

【CF1020E】Sergey's problem(构造)的更多相关文章

  1. Codeforces 1019C Sergey's problem 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1019C.html 题目传送门 - CF1019C 题意 给定一个有 $n$ 个节点 . $m$ 条边的有向 ...

  2. [CF1019C]Sergey's problem[构造]

    题意 找出一个集合 \(Q\),使得其中的点两两之间没有连边,且集合中的点可以走不超过两步到达其他所有不在集合中的点.输出任意一组解. \(n\leq 10^6\) 分析 考虑构造,先从 \(1\) ...

  3. Codeforces Round #503 (by SIS, Div. 2) E. Sergey's problem

    E. Sergey's problem [题目描述] 给出一个n个点m条边的有向图,需要找到一个集合使得1.集合中的各点之间无无边相连2.集合外的点到集合内的点的最小距离小于等于2. [算法] 官方题 ...

  4. 【Cf #503 C】Sergey's problem(有趣的构造)

    感觉这种构造题好妙啊,可我就是想不到诶. 给出一张无自环的有向图,回答一个独立集,使得图中任意一点都可以被独立集中的某一点两步之内走到. 具体构造方案如下: 下标从小到大枚举点,如果该点没有任何标记, ...

  5. Sergey's problem CodeForces - 1019C (图论,构造,神题)

    链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...

  6. CF1019C Sergey's problem (图上构造)

    题目大意:给你一个有向连通图,让你找出一个点集,保证点集内的点之间没有直接连边,且集合中存在一点,到一个 非点集中的点的距离小于等于2 思路很清奇 首先编号从小到大遍历每个点,如果这个点没有被访问过, ...

  7. HDU 5402 Travelling Salesman Problem (构造)(好题)

    大致题意:n*m的非负数矩阵,从(1,1) 仅仅能向四面走,一直走到(n,m)为终点.路径的权就是数的和.输出一条权值最大的路径方案 思路:因为这是非负数,要是有负数就是神题了,要是n,m中有一个是奇 ...

  8. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

  9. hdu 1757 A Simple Math Problem (构造矩阵解决递推式问题)

    题意:有一个递推式f(x) 当 x < 10    f(x) = x.当 x >= 10  f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + ...

随机推荐

  1. 1014-32-首页13-cell的结构分析---导航栏中间title位置的按钮的尺寸设置---setFrame----

    #import "HWTitleButton.h" #define HWMargin 5 @implementation HWTitleButton - (id)initWithF ...

  2. BFS例题:A计划

    ContribContrib/a11y/accessibility-menu.js 关于 BFS要点: 1.若为可化为的坐标系图形,可用结构体存储其x值,y值和步数.(一般开now 和 next ,n ...

  3. 我今天的收获,必备stadio 插件

    1.ADBWIFI 必须的,说不定你就用到了. 2.ADB Idea 必须 3.JavaDoc 4.Translation 5.Gradle Killer

  4. 把实体bean对象转换成DBObject工具类

    import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util ...

  5. laravel5.5事件广播系统实例laravel-echo + redis + socket.io

    目录 1. 广播配置说明 1.1 广播驱动配置 1.2 注册服务提供器 2. 驱动器配置 2.1 安装predis 2.2. 配置服务端 2.2.1 安装方法 2.2.2 初始化服务端 2.2.3 运 ...

  6. shuffle的过程分析

    shuffle的过程分析 shuffle阶段其实就是之前<MapReduce的原理及执行过程>中的步骤2.1.多个map任务的输出,按照不同的分区,通过网络copy到不同的reduce节点 ...

  7. 网易考拉Android客户端网络模块设计

    本文来自网易云社区 作者:王鲁才 客户端开发中不可避免的需要接触到访问网络的需求,如何把访问网络模块设计的更具有扩展性是每一个移动开发者不得不面对的事情.现在有很多主流的网络请求处理框架,如Squar ...

  8. Spring进阶—如何用Java代码实现邮件发送(一)

    相关文章: <Spring进阶—如何用Java代码实现邮件发送(二)> 在一些项目里面如进销存系统,对一些库存不足发出预警提示消息,招聘网站注册用户验证email地址等都需要用到邮件发送技 ...

  9. 【Minimum Window】cpp

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  10. JavaScript简易学习笔记

    学习地址:http://www.w3school.com.cn/js/index.asp 文字版: https://github.com/songzhenhua/github/blob/master/ ...