06-图7. How Long Does It Take (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

Given the relations of all the activities of a project, you are supposed to find the earliest completion time of the project.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (<=100), the number of activity check points (hence it is assumed that the check points are numbered from 0 to N-1), and M, the number of activities. Then M lines follow, each gives the description of an activity. For the i-th activity, three non-negative numbers are given: S[i], E[i], and L[i], where S[i] is the index of the starting check point, E[i] of the ending check point, and L[i] the lasting time of the activity. The numbers in a line are separated by a space.

Output Specification:

For each test case, if the scheduling is possible, print in a line its earliest completion time; or simply output "Impossible".

Sample Input 1:

9 12
0 1 6
0 2 4
0 3 5
1 4 1
2 4 1
3 5 2
5 4 0
4 6 9
4 7 7
5 7 4
6 8 2
7 8 4

Sample Output 1:

18

Sample Input 2:

4 5
0 1 1
0 2 2
2 1 3
1 3 4
3 2 5

Sample Output 2:

Impossible

提交代码

AOV图。拓扑排序。

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
int Map[][],dist[],indegree[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m;
int i,j,a,b,cost;
scanf("%d %d",&n,&m);
for(i=;i<n;i++){
dist[i]=-;
indegree[i]=;
for(j=;j<n;j++){
Map[i][j]=Map[j][i]=-;
}
}
for(i=;i<m;i++){
scanf("%d %d %d",&a,&b,&cost);
Map[a][b]=cost;
indegree[b]++;
}
queue<int> q;
for(i=;i<n;i++){
if(!indegree[i]){
q.push(i);
dist[i]=;//这个初始化很重要
}
}
int cur;
while(!q.empty()){
cur=q.front();
q.pop();
for(i=;i<n;i++){
if(Map[cur][i]!=-){
indegree[i]--;
if(dist[cur]+Map[cur][i]>dist[i]){
dist[i]=dist[cur]+Map[cur][i];
}
if(!indegree[i]){
q.push(i);
}
}
}
}
int maxcost=-;
for(i=;i<n;i++){
if(indegree[i]){
break;
}
if(dist[i]>maxcost){
maxcost=dist[i];
}
}
if(i==n){
printf("%d\n",maxcost);
}
else{
printf("Impossible\n");
}
return ;
}

pat06-图7. How Long Does It Take (25)的更多相关文章

  1. 封装构造函数,用canvas写饼状图和柱状图

    封装构造函数,用canvas写饼状图和柱状图 封装函数 // 场景 function XDLScence( options ) { this.stage = options.stage; //执行场景 ...

  2. R语言基础

    一.扩展包的基本操作语句R安装好之后,默认自带了"stats" "graphics"  "grDevices" "utils&qu ...

  3. 【转载】MATLB绘图

    原文地址:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 作为一个功能强大的工具软件,Matlab具有很强的图形处理功能,提供 ...

  4. (转载)MatLab绘图

    转载自:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 转载自:http://www.cnblogs.com/jeromebl ...

  5. android122 zhihuibeijing 新闻中心NewsCenterPager加载网络数据实现

    新闻中心NewsCenterPager.java package com.itheima.zhbj52.base.impl; import java.util.ArrayList; import an ...

  6. OpenCV探索之路(三):滤波操作

    滤波处理分为两大类:线性滤波和非线性滤波.OpenCV里有这些滤波的函数,使用起来非常方便,现在简单介绍其使用方法. 线性滤波:方框滤波.均值滤波.高斯滤波 方框滤波 #include<open ...

  7. Android图像处理 - 高斯模糊的原理及实现

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 由 天天P图攻城狮 发布在云+社区 作者简介:damonxia(夏正冬),天天P图Android工程师 前言 高斯模糊是图像处理中几乎每个程序员 ...

  8. Python爬取南京市往年天气预报,使用pyecharts进行分析

    上一次分享了使用matplotlib对爬取的豆瓣书籍排行榜进行分析,但是发现python本身自带的这个绘图分析库还是有一些局限,绘图不够美观等,在网上搜索了一波,发现现在有很多的支持python的绘图 ...

  9. 卷积神经网络之LeNet

    开局一张图,内容全靠编. 上图引用自 [卷积神经网络-进化史]从LeNet到AlexNet. 目前常用的卷积神经网络 深度学习现在是百花齐放,各种网络结构层出不穷,计划梳理下各个常用的卷积神经网络结构 ...

  10. 【Java基础】【25多线程(下)&GUI】

    25.01_多线程(单例设计模式)(掌握) 单例设计模式:保证类在内存中只有一个对象. 如何保证类在内存中只有一个对象呢? (1)控制类的创建,不让其他类来创建本类的对象.private (2)在本类 ...

随机推荐

  1. c# 制作悬浮框

    一,制作winform 窗体 窗体要做小一点,你见过500*500的悬浮框吗? 二,去掉边框和标题栏 this.FormBorderStyle = FormBorderStyle.None; 运行出来 ...

  2. 关于AJAX异步加载节点无法触发点击事件问题的解决方式

    做练习的过程中遇到一个问题,使用AJAX异步新增一个节点,无法触发点击事件,经过查阅之后知道一个方式,使用JS的委托事件,在此做一个记录. $(document).on('click', '.recr ...

  3. Java实现终止线程池中正在运行的定时任务

    源于开发 最近项目中遇到了一个新的需求,就是实现一个可以动态添加定时任务的功能.说到这里,有人可能会说简单啊,使用quartz就好了,简单粗暴.然而quartz框架太重了,小项目根本不好操作啊.当然, ...

  4. 洛谷 P1879 [USACO06NOV]玉米田Corn Fields

    题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...

  5. win10下安装配置mysql-8.0.13--实战可用

    1.下载mysql-8.0.13安装包 1 https://dev.mysql.com/downloads/mysql/ 选择zip安装包下载就好. 2.解压到你要安装的目录 3.创建my.ini配置 ...

  6. [SinGuLaRiTy] 高一下半期测试

    [SinGuLaRiTy-1017] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有的题目: Time Limit: 1s | Me ...

  7. chrome插件-YSlow 一个使用的web性能测试插件

    本文为转载是文章,如作者发现后不愿意,请联系我进行删除 原文链接:http://www.cnblogs.com/wajika/p/6278825.html YSlow的安装: 1.安装 firebug ...

  8. 常用linux基础命令(持续更新...)

    删除 空目录 rmdir非空目录 rm -rf 目录名字-r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思 删除文件命令rm -f 文件名将会强行删除文件,且无提 ...

  9. 数据结构11: 栈(Stack)的概念和应用及C语言实现

    栈,线性表的一种特殊的存储结构.与学习过的线性表的不同之处在于栈只能从表的固定一端对数据进行插入和删除操作,另一端是封死的. 图1 栈结构示意图 由于栈只有一边开口存取数据,称开口的那一端为“栈顶”, ...

  10. CF709A Juicer 模拟

    Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put ...