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. win7 配置 用户/系统DSN (解决plsql odbc导入器 DSN 没有选项)

    (2013-05-07 15:07:29) 转载▼ 标签: it   老笔记本越来越卡,最近重新做了win7的系统 从sql server中导出的 excel文件 准备通过plsql倒入的oracle ...

  2. oracle不记得所有账户和密码怎么办

    1.打开cmd,输入sqlplus /nolog,回车: 2.输入“conn / as sysdba”; 3.输入“alter user sys identified by 新密码:”,注意:必须输入 ...

  3. 【Jmeter源码解读】002——程序入口类NewDriver.java

    1.运行环境的检查 2.刚才初始化的 classloader 加载类 org.apache.jmeter.JMeter 然后通过 java 反射的方式来调用 org.apache.jmeter.JMe ...

  4. Numbers(CodeForces-128D)【思维/list】

    题目链接:https://vjudge.net/problem/CodeForces-128D 题意:给出一组数,要求将这些数排列成一个环,满足每相邻两个数的差值为1,问能否完成. 思路:先取出最小的 ...

  5. Go语言学习之斐波那契数列的测试例子和定义常量方法

    ### Go语言学习之斐波那契数列的测试例子和定义常量方法 1.go语言中测试文件必须以test.go结尾,比如:fib_test.go 2.测试文件内的方法必须是Test开头,比如:func Tes ...

  6. codeblocks 使用汇总

    codeblocks 使用汇总 http://www.cnblogs.com/-clq/archive/2012/01/31/2333247.html

  7. C++通用框架和库

    C++通用框架和库 来源 https://www.cnblogs.com/skyus/articles/8524408.html 关于 C++ 框架.库和资源的一些汇总列表,内容包括:标准库.Web应 ...

  8. Swagger学习(三、配置扫描接口)

    生产环境中使用,发布的时候不能使用

  9. QT版本下载链接

    http://download.qt.io/archive/qt/

  10. PHP中pdo的使用

    <?php /** *下面代码中information为表名 * */ //1.先要连数据库 $pdo=new PDO('mysql:host=localhost;dbname=数据库名','用 ...