题意:

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

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

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 1100000
#define M 51
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 3e14 vector<int> c[N];
int a[N],b[N],q[N]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) c[i].clear();
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
c[x].push_back(y);
}
for(int i=;i<=n;i++)
if(!a[i])
{
for(int j=;j<=(int)c[i].size()-;j++) a[c[i][j]]=;
a[i]=b[i]=;
}
for(int i=n;i>=;i--)
if(b[i])
{
for(int j=;j<=(int)c[i].size()-;j++) b[c[i][j]]=;
}
int ans=;
for(int i=;i<=n;i++)
if(b[i]) q[++ans]=i;
printf("%d\n",ans);
for(int i=;i<=ans-;i++) printf("%d ",q[i]);
printf("%d\n",q[ans]);
return ;
}

【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. tcl之文件操作-文件名相关

  2. 创建数据库配置文件ini(转)

    一.有必要了解INI文件的结构: ;注释 [小节名] 关键字=值 ... ---- INI文件允许有多个小节,每个小节又允许有多个关键字, “=”后面是该关键字的值. ---- 值的类型有三种:字符串 ...

  3. HDU 5446 Unknown Treasure (卢卡斯+CRT

    代码: #include"bits/stdc++.h" #define db double #define ll long long #define vec vector<l ...

  4. Android Stadio 相关

    这几天,电脑坏了.重装系统,慢慢的学到了很多Android stadio 的相关知识.总结一下吧: 1.gradle 编译工具:在工程的gradle/wrapper/gradle–wrapper.pr ...

  5. Android Studio自定义模板代码

    http://blog.csdn.net/h183288132/article/details/51916399 生成模板看上面这个博客就可以了,不再重复制造轮子. 不过需要补充的是: 还应该有下面的 ...

  6. SetConsoleCtrlHandler

    Excerpt: Registering a Control Handler Function   This is an example of the SetConsoleCtrlHandler fu ...

  7. 使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录

    使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录 时间:2012年9月20日 分类:JavaScript 标签:HTML5‚ jQuery Mobile‚ Web ...

  8. AS3项目基础框架搭建分享robotlegs2 + starling1.3 + feathers1.1

    这个框架和我之前使用robotlegs1版本的大体相同,今天要写一个新的聊天软件就把之前的框架升级到了2.0并且把代码整理了一下. 使用适配器模式使得starling的DisplayObject和fl ...

  9. Jmeter日期

    有的时候我们接口中会有需要传递日期的参数,这是jmeter工具中给我准备一个 日期函数_time,如下图所示: 取到的将会是年月日 对应的写法有 yyyy-MM-dd HH:mm:ss  ---年月日 ...

  10. selenium初识(一)

    Selenium是一个开源的便携式的自动化软件测试工具,用于测试web应用程序.有能力在不同浏览器和操作系统运行.它是一套工具,帮助我们有效地给予web应用程序的自动化. Selenium分为以下几个 ...