Codeforces Round #455 (Div. 2) 909E. Coprocessor
题
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的更多相关文章
- Codeforces Round #455 (Div. 2)
Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...
- Codeforces Round #455 (Div. 2) 909D. Colorful Points
题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...
- 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 ...
- 【Codeforces Round #455 (Div. 2) A】Generate Login
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举两个串的前缀长度就好. 组出来. 排序. 取字典序最小的那个. [代码] #include <bits/stdc++.h& ...
- 【Codeforces Round #455 (Div. 2) B】Segments
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出所有的线 其实就是区间. 总共有n*(n+1)/2个 然后按照左端点.右端点排序 每次取最左边的线. 多种可能就取右端点尽量小 ...
- 【Codeforces Round #455 (Div. 2) C】 Python Indentation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...
- 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 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- [转帖]「知乎知识库」— 5G
「知乎知识库」— 5G 甜草莓 https://zhuanlan.zhihu.com/p/55998832 通信 话题的优秀回答者 已关注 881 人赞同了该文章 谢 知识库 邀请~本文章是几个答 ...
- tomcat单机多应用部署配合Nginx负载均衡
一.Windows 配置tomcat . 安装两个tomcat服务器以上 . 配置环境变量 CATALINA_BASE:D:\servers\Tomcat8 CATALINA_HOME:D:\serv ...
- (十三)mybatis 整合 ehcache
目录 ehcache mybatis 的 Cache 接口 整合步骤 ehcache ehcache 是一个分布式缓存框架 ! 为什么需要分布式缓存? 在大型的项目中,服务器是肯定不止一台的,每台服务 ...
- 连续取数字DP使值最大HDU2697
题意: 有n个数,每个数都有价钱,连续的取可以获得len*len的利益,使利益最大. 思路: 三维DP,1.2.3维分别是第i个,剩余多少钱,从后往前连续的有几个. #define IOS ios_b ...
- 【背包问题】PACKING
题目描述 It was bound to happen. Modernisation has reached the North Pole. Faced with escalating costs ...
- k8s-日志收集架构
日志收集 Kubernetes 集群中监控系统的搭建,除了对集群的监控报警之外,还有一项运维工作是非常重要的,那就是日志的收集. 介绍 应用程序和系统日志可以帮助我们了解集群内部的运行情况,日志对于我 ...
- linux下的终端利器 tmux 安装以及使用
ref :https://www.jianshu.com/p/fd3bbdba9dc9 Introduction 为什么使用tmux? 因为如果我们用terminal连接remote server.发 ...
- javascript 构建模块化开发
在使用 sea.js .require.js . angular 的时候. 我们使用到 define . module(require) 的方式,定义模块,和依赖模块 下面给出 define 和 m ...
- Antd组件库,利用Menu组件模拟一个简单Tree组件
当前工作中,前端的主要技术栈用是vue. 那React怎么办呢?总不至于把他扔在墙角吧! 只能在一些很小的项目上,也只有自己一个前端的时候,悄悄的上React. 当然,React项目UI组件还是最喜欢 ...
- Scala学习二十——Actor
一.本章要点 每个actor都要扩展Actor类并提供act方法 要往actor发送消息,可以用actor!message 消息发送是异步的:”发完就忘“ 要接受消息,actor可以调用receive ...