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 ...
随机推荐
- SQLSever语句(增、删、改、查)一、增:有4种方法1.使用insert插入单行数据
SQL语句(增.删.改.查) 一.增:有4种方法 1.使用insert插入单行数据: 语法:insert [into] <表名> [列名] values <列值> 例:inse ...
- request方法
获取请求行方法: getMethod()获取请求的方法 getContextPath()回去虚拟路径 getServletPath()获取路径(只有在servert中使用) getQueryStrin ...
- 将neo4j的一个节点上的关系移动到另一个节点上
将neo4j中一个节点的全部关系移动到另一个节点上面,采用先建立新关系,之后删除原先的关系的方式 def move_relations(source_node_id,target_node_id,gr ...
- java版MD5签名工具类
package com.net.util; import java.security.MessageDigest; /** * MD5签名工具类 * @author zhangdi * */ publ ...
- 2019上海网络赛 F. Rhyme scheme 普通dp
Rhyme scheme Problem Describe A rhyme scheme is the pattern of rhymes at the end of each line of a p ...
- NOIP 2018 提高组初赛试题 题目+答案+简要解析
一.单项选择题(共 10 题,每题 2 分,共计 20 分: 每题有且仅有一个正确选项) 1. 下列四个不同进制的数中,与其它三项数值上不相等的是( ). A. (269) 16 B ...
- Prometheus Operator 自动发现和持久化
Prometheus Operator 自动发现和持久化 之前在 Prometheus Operator 下面自定义一个监控选项,以及自定义报警规则的使用.那么我们还能够直接使用前面课程中的自动发现功 ...
- 怎样写一个Hello World!
Python 的 Hello, World! 应该是所有语言里面最简单的: print("Hello, World!")
- 怎样通过html标签名获取元素节点集合
方法1. 使用document.querySelectorAll(); 方法2. 使用document.getElementsByTagName(); document.querySelectorAl ...
- JSON格式互转集合 (2)
public class JSON { public static string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"; ...