题意略。

思路:一个拓扑排序的题目吧。肯定是要先处理后面那个任务,再处理前面那个任务,我的思路是尽力先把主处理器能操作的先操作完,然后再把副处理器能操作完的再操作完,这样循环,直到处理完全部。

定义total变量为已经处理完的任务总数。

详见代码:

#include<bits/stdc++.h>
#define maxn 100005
using namespace std; int mark[maxn],indegree[maxn];
vector<int> graph[maxn];
int N,M;
queue<int> que[]; int main(){
scanf("%d%d",&N,&M);
for(int i = ;i < N;++i) scanf("%d",&mark[i]);
int u,v;
for(int i = ;i < M;++i){
scanf("%d%d",&u,&v);
graph[v].push_back(u);
indegree[u] += ;
}
int ans = ;
int total = N;
for(int i = ;i < N;++i){
if(indegree[i] == ){
que[mark[i]].push(i);
}
}
while(total > ){
while(que[].size()){
int temp = que[].front();
que[].pop();
total -= ;
for(int i = ;i < graph[temp].size();++i){
int nxt = graph[temp][i];
indegree[nxt] -= ;
if(indegree[nxt] == )
que[mark[nxt]].push(nxt);
}
}
if(total == ) break;
ans += ;
while(que[].size()){
int temp = que[].front();
que[].pop();
total -= ;
for(int i = ;i < graph[temp].size();++i){
int nxt = graph[temp][i];
indegree[nxt] -= ;
if(indegree[nxt] == )
que[mark[nxt]].push(nxt);
}
}
}
if(que[].size()) ans += ;
printf("%d\n",ans);
return ;
}

CodeForces 909E的更多相关文章

  1. CodeForces 909E Coprocessor(无脑拓扑排序)

    You are given a program you want to execute as a set of tasks organized in a dependency graph. The d ...

  2. Codeforces 909E. Coprocessor (拓扑、模拟)

    题目链接: Coprocessor 题意: 给出n个待处理的事件(0 - n-1),再给出了n个标(0表示只能在主处理器中处理这个事件,1表示只能在副处理器中处理这个事件),处理器每次能处理多个任务. ...

  3. CodeForces 909E Coprocessor

    题解. 贪心,拓扑排序. 和拓扑排序一样,先把$flag$为$0$的点能删的都删光,露出来的肯定都是$flag$为$0$的,然后疯狂删$flag$为$0$的,这些会使答案加$1$,反复操作就可以了. ...

  4. Codeforces 909E(Coprocessor,双队列维护)

    题意:给出n个待处理的事件(0 ~n-1),再给出了n个标(0表示只能在主处理器中处理这个事件,1表示只能在副处理器中处理这个事件),处理器每次能处理多个任务.每个事件有关联,如果一个任务要在副处理器 ...

  5. Codeforces Round #455 (Div. 2) 909E. Coprocessor

    题 OvO http://codeforces.com/contest/909/problem/E CF455 div2 E CF 909E 解 类似于拓扑排序地进行贪心, 对于 Ei=0 并且入度为 ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. 简单web网页与SSM后台交互

    简单web网页与SSM后台交互 情况说明 如今,已经搭建好SSM后台开发环境,并且可以经由postman工具测试成功.现在尝试写出web前端网页,通过实现简单的提交.注册.查询功能来加深对前后端数据传 ...

  2. python课堂整理20----生产者消费者模型

    一.实现功能:店铺生产包子,消费者来吃 import time def producter(): ret = [] for i in range(10): time.sleep(0.1) ret.ap ...

  3. 初探java流操作

    在处理集合时,我们通常会迭代遍历它的元素,并从每个元素上执行某项操作.例如,假设我们想要对某本书中的所有长单词进行计数.首先我们要将所有单词放入一个列表中: String contents = new ...

  4. jsp的简介(1)

    一.什么是Java Server Pages? JSP全称Java Server Pages,是一种动态网页开发技术.它使用JSP标签在HTML网页中插入Java代码.标签通常以<%开头以%&g ...

  5. 用ECharts绘制Prometheus图表,实现类似Grafana的自定义Dashboard

      大家一般都是用Grafana自定义Dashboard来监控Prometheus数据的,作者这次尝试用ECharts来绘制Prometheus数据图表,一方面可以减少依赖,另一方面可以将监控界面灵活 ...

  6. python post接口测试第一个用例日记

    如下是我自己公司的一个请求,学习过程顺便记录下,都是白话语言,不那么专业,不喜勿喷! 首先看下图,post请求一般需要填写参数url, data(一般是表格类型的参数,如我们智联驾驶APP登录的参数) ...

  7. js里的Document对象介绍

    activeElement     返回代表文档中dangqianhuodejiaodianyuansudeduixaing body                    返回代表文档中body元素 ...

  8. docker的基本安装和命令详解

    docker的安装 yum install docker-io docker的启动 /bin/systemctl start docker.service docker查找镜像 docker sear ...

  9. SpringMVC学习笔记之---深入使用

    SpringMVC深入使用 (一)基于XML配置的使用 (1)配置 1.SpringMVC基础配置 2.XML配置Controller,HandlerMapping组件映射 3.XML配置ViewRe ...

  10. javascript基础案例解析

    学完了JavaScript基础部分,总结出一些基本案例,以备日后查看! 1.九九乘法口诀表:在控制台中输出九九乘法口诀表!代码如下: <!DOCTYPE html> <html> ...