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 ...
随机推荐
- Ember.js和Vue.js,哪种框架更适合你?
JavaScript最初是为Web应用程序而创建的.随着前端技术的发展,比起纯JavaScript 脚本,大多数开发人员更喜欢使用基于JavaScript的框架来开发Web应用,如Vue.React等 ...
- shiro整合shiro多验证登录(账号密码登录和使用手机验证码登录)
1. 首先新建一个shiroConfig shiro的配置类,代码如下: @Configuration是标识这个类是一个配置文件,在启动时会加载这个类里面的内容,这个配置文件的位置的一定一定一定不能 ...
- 【k8s第二步】Kubernetes-Kubeadm部署安装【已修正错误】
⒈开启kube-proxy的ipvs的前置条件 模式改为lvs调度的方式,kube-proxy主要解决的是svc(service)与pod之间的调度关系,ipvs的调度方式可以极大的增加它的访问效率, ...
- Kubernetes---网络通讯模式笔记
⒈kubernetes网络通讯模式 Kubernetes的网络模型假定了所有Pod都在一个可以直接连通的扁平的网络空间中,这在GCE(Google Compute Engine)里面是现成的网 ...
- hdu 6319 逆序建单调队列
题目传送门//res tp hdu 维护递增单调队列 根据数据范围推测应为O(n)的. 我们需要维护一个区间的信息,区间内信息是"有序"的,同时需要在O(1)的时间进行相邻区间的信 ...
- MGR+Consul集群
[root@mydb1 ~]# wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip[root@m ...
- 如何理解归一化(Normalization)对于神经网络(深度学习)的帮助?
如何理解归一化(Normalization)对于神经网络(深度学习)的帮助? 作者:知乎用户链接:https://www.zhihu.com/question/326034346/answer/730 ...
- Core项目部署到IIS上delete、put谓词不支持
解决方法:在web.config的system.webServer结点下添加如下代码 <modules runAllManagedModulesForAllRequests="true ...
- javaIO——PushbackReader
1. 注释解释: A character-stream reader that allows characters to be pushed back into the stream. 一个允许字符被 ...
- ajax 请求二进制流 图片
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> ...