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. MasterPage + UpdatePanel + FileUpload

    上传文件在母版页与Ajax的UpdatePanel的环境进行.由于在母版内使用Ajax,建议使用AjaxControlToolkit.dll组件,去微软官网下载后,并拉入BIN目录中. 然后去web. ...

  2. UIPasteboard

    1.UIPasteboard 简介 顾名思义,UIPasteboard 是剪切板功能,因为 iOS 的原生控件 UITextField.UITextView.UIWebView, 我们在使用时如果长按 ...

  3. Python中dataframe\ array\ list相互转化

    import pandas as pd import numpy as np #创建列表 a1=[1,2,3] #arange函数:指定初始值.终值.步长来创建数组 a2=np.arange(0,1, ...

  4. day01.2-计算机网络协议

    注:本文摘自林海峰老师的博客,作为个人学习笔记,日后方便阅读,原文详见链接www.cnblogs.com/linhaifeng/articles/5937962.html 一.  ISO协议     ...

  5. vue 用axios实现调用接口下载excel

    了解的方式有两种: 1. 用a标签,href设置为后端提供的excel接口 <a href="excel接口">导出</a> 简单方便,缺点就是当有toke ...

  6. 为什么选择Angular 2?

    没有选择是痛苦的,有太多的选择却更加痛苦.而后者正是目前前端领域的真实写照.新的框架层出不穷:它难吗?它写得快吗?可维护性怎样?运行性能如何?社区如何?前景怎样?好就业吗?好招人吗?组建团队容易吗? ...

  7. 适配器设计模式初探(Java实现)

    本篇随笔主要介绍Java实现设配器设计模式. 先来看下待解决的问题: (图片转自http://blog.csdn.net/jason0539) 由上图的情况可知,欧洲壁式插座只有三足插口,如果我们想要 ...

  8. 2019年GPLT L2-3 深入虎穴 比赛题解 中国高校计算机大赛-团体程序设计天梯赛题解

    著名的王牌间谍 007 需要执行一次任务,获取敌方的机密情报.已知情报藏在一个地下迷宫里,迷宫只有一个入口,里面有很多条通路,每条路通向一扇门.每一扇门背后或者是一个房间,或者又有很多条路,同样是每条 ...

  9. kuangbin专题七 HDU1754 I Hate It (单点修改维护最大值)

    很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有 ...

  10. 在生产环境下禁用swagger

    学习目标 快速学会使用注解关闭Swagger2,避免接口重复暴露. 使用教程 禁用方法1:使用注解@Profile({"dev","test"}) 表示在开发或 ...