OvO http://codeforces.com/contest/909/problem/E

  CF455 div2 E

  CF 909E

  类似于拓扑排序地进行贪心,

  对于 Ei=0 并且入度为 0 的点,创建一个缓冲队列,把这些点的影响到的点先放到缓冲队列中,然后等一次 coprocessor calls 计算完后统一处理,保证每次找 coprocessor calls 的集合的时候,缓冲队列为空

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue> using namespace std; const int N=1e5+44; struct node{
int u,v;
int next;
}edge[2*N]; int head[N],num,tag[N];
int n,m;
int indg[N];
int que[N],lq,rq;
queue<int> dlt_wait; void addedge(int u,int v)
{
edge[num].u=u;
edge[num].v=v;
edge[num].next=head[u];
head[u]=num++;
} void init()
{
num=0;
memset(head,-1,sizeof(head));
} void dlt(int id)
{
for(int i=head[id];i!=-1;i=edge[i].next)
dlt_wait.push(edge[i].v);
} void clean()
{
int now;
while(!dlt_wait.empty())
{
now=dlt_wait.front(),dlt_wait.pop();
if(--indg[now]==0)
{
if(tag[now])
que[++rq]=now;
else
dlt(now);
}
}
} void solve()
{
int tmp,now;
int ans=0;
lq=1,rq=0;
while(!dlt_wait.empty())
dlt_wait.pop();
for(int i=0;i<n;i++)
if(indg[i]==0)
{
if(tag[i])
que[++rq]=i;
else
dlt(i);
}
clean();
while(lq<=rq)
{
ans++;
while(lq<=rq)
{
now=que[lq++];
for(int i=head[now];i!=-1;i=edge[i].next)
if(--indg[edge[i].v]==0)
{
if(tag[edge[i].v])
que[++rq]=edge[i].v;
else dlt(edge[i].v);
}
}
clean();
}
printf("%d\n",ans);
} int main()
{
int a,b;
memset(indg,0,sizeof(indg));
init();
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",&tag[i]);
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
addedge(b,a);
indg[a]++;
}
solve();
return 0;
}

  

Codeforces Round #455 (Div. 2) 909E. Coprocessor的更多相关文章

  1. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...

  2. Codeforces Round #455 (Div. 2) 909D. Colorful Points

    题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...

  3. Codeforces Round #455 (Div. 2) A. Generate Login【贪心】

    A. Generate Login time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. 【Codeforces Round #455 (Div. 2) A】Generate Login

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举两个串的前缀长度就好. 组出来. 排序. 取字典序最小的那个. [代码] #include <bits/stdc++.h& ...

  5. 【Codeforces Round #455 (Div. 2) B】Segments

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出所有的线 其实就是区间. 总共有n*(n+1)/2个 然后按照左端点.右端点排序 每次取最左边的线. 多种可能就取右端点尽量小 ...

  6. 【Codeforces Round #455 (Div. 2) C】 Python Indentation

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...

  7. Codeforces Round #455 (Div. 2) D题(花了一个早自习补了昨晚的一道模拟QAQ)

    D. Colorful Points You are given a set of points on a straight line. Each point has a color assigned ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. 【转贴】linux 终端报Message from syslogd

    linux 终端报Message from syslogd xiao9873341760人评论8537人阅读2017-03-27 14:19:31 https://blog.51cto.com/xia ...

  2. LUA的table实现

    数据结构 下面的结构体是lua中所定义的table typedef struct Table { CommonHeader; lu_byte flags; /* 1<<p means ta ...

  3. (二十五)JDBC多表查询

    java易错点 一对多 VS 多对一 VS 多对多 级联 多表增删改 多对多表设计语句(学生老师) java易错点 数组初始化的时候,可以用 {} 赋值,初始化以后,只能用 new Object[] ...

  4. HDU 3333-Turing Tree-线段树+离散+离线

    Description After inventing Turing Tree, 3xian always felt boring when solving problems about interv ...

  5. 20190804-Python基础 第二章 列表和元组

    容器,Python支持一种数据结构的基本概念(容器,基本上就是可包含其他对象的对象.) 两种主要的容器是:序列(如列表和元组)和映射(如字典) Ps: 列表与元组区别,列表可修改,元组不能. 对序列的 ...

  6. 第九章 MIZ702 ZYNQ片上ADC的使用

      9.0难度系数★☆☆☆☆☆☆ 9.1实验概述 这次借助zynq的内嵌的XADC来采集zynq内部的一些参数: •VCCINT:内部PL核心电压 •VCCAUX:辅助PL电压 •VREFP:XADC ...

  7. echarts 根据经纬度坐标在地图上描点

    var mapData = [ {'latitude':30.67, 'longitude':104.07}, {'latitude':34.76, 'longitude':113.65}, {'la ...

  8. Spring 自定义Bean 实例获取

    一.通过指定配置文件获取, 对于Web程序而言,我们启动spring容器是通过在web.xml文件中配置,这样相当于加载了两次spring容器 ApplicationContext ac = new ...

  9. 获取windows进程信息及CListCtrl控件(List Control)练习

    环境:VS2010/MFC/对话框 效果图: 目录: 1.  关于windows进程信息获取 2.  CListCtrl的使用 ------------------------------------ ...

  10. python selenium2 模拟点击+拖动 测试对象 58同城验证码

    #!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019/12/5 17:30 # @Author : shenghao/10347899@qq ...