pat06-图7. How Long Does It Take (25)
06-图7. How Long Does It Take (25)
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)的更多相关文章
- 封装构造函数,用canvas写饼状图和柱状图
封装构造函数,用canvas写饼状图和柱状图 封装函数 // 场景 function XDLScence( options ) { this.stage = options.stage; //执行场景 ...
- R语言基础
一.扩展包的基本操作语句R安装好之后,默认自带了"stats" "graphics" "grDevices" "utils&qu ...
- 【转载】MATLB绘图
原文地址:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 作为一个功能强大的工具软件,Matlab具有很强的图形处理功能,提供 ...
- (转载)MatLab绘图
转载自:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 转载自:http://www.cnblogs.com/jeromebl ...
- android122 zhihuibeijing 新闻中心NewsCenterPager加载网络数据实现
新闻中心NewsCenterPager.java package com.itheima.zhbj52.base.impl; import java.util.ArrayList; import an ...
- OpenCV探索之路(三):滤波操作
滤波处理分为两大类:线性滤波和非线性滤波.OpenCV里有这些滤波的函数,使用起来非常方便,现在简单介绍其使用方法. 线性滤波:方框滤波.均值滤波.高斯滤波 方框滤波 #include<open ...
- Android图像处理 - 高斯模糊的原理及实现
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 由 天天P图攻城狮 发布在云+社区 作者简介:damonxia(夏正冬),天天P图Android工程师 前言 高斯模糊是图像处理中几乎每个程序员 ...
- Python爬取南京市往年天气预报,使用pyecharts进行分析
上一次分享了使用matplotlib对爬取的豆瓣书籍排行榜进行分析,但是发现python本身自带的这个绘图分析库还是有一些局限,绘图不够美观等,在网上搜索了一波,发现现在有很多的支持python的绘图 ...
- 卷积神经网络之LeNet
开局一张图,内容全靠编. 上图引用自 [卷积神经网络-进化史]从LeNet到AlexNet. 目前常用的卷积神经网络 深度学习现在是百花齐放,各种网络结构层出不穷,计划梳理下各个常用的卷积神经网络结构 ...
- 【Java基础】【25多线程(下)&GUI】
25.01_多线程(单例设计模式)(掌握) 单例设计模式:保证类在内存中只有一个对象. 如何保证类在内存中只有一个对象呢? (1)控制类的创建,不让其他类来创建本类的对象.private (2)在本类 ...
随机推荐
- MVC Areas
ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规则去组织model实体层,views视图层和控制层的.如果是大规模的应用程序,经常会由不同功能的模块组成,而每个功能模块都由MVC中的三层所 ...
- android中SharedPreferences 读取不到数据的问题
在两个不同的 Activity中,A中SharedPreferences保存了数据,在A中可以读取到,但是在 B中却读取不到了,一直是空值,好是不爽,由于是按照书本上的例子写的, 怎么也找不到原因,后 ...
- C#泛型理解(一)
一.什么是泛型 泛型是C#语言和公共语言运行库(CLR)中的一个新功能,它将类型参数的概念引入.NET Framework.类型参数使得设计某些类和方法成为可能,例如,通过使用泛型类型参数T,可以大大 ...
- 动态横向(水平)合并GridView数据行DataRow的列
前一段时间,Insus.NET有写过<动态合并GridView数据行DataRow的列>http://www.cnblogs.com/insus/p/3238348.html, 那是纵向( ...
- Gazebo学习随记4 Actor: 该配合你的演出我视而不见
在Gazebo仿真中,除了模型model外,还有一种和model并列的类型——actor. 相比于model受物理引擎的作用,actor不受重力等等的影响,可以按照设定的运动轨迹进行运动. <s ...
- 算法提高 合并石子(DP)
问题描述 在一条直线上有n堆石子,每堆有一定的数量,每次可以将两堆相邻的石子合并,合并后放在两堆的中间位置,合并的费用为两堆石子的总数.求把所有石子合并成一堆的最小花费. 输入格式 输入第一行包含一个 ...
- go语言实战教程之 后台管理页面统计功能开发(2)
上节内容介绍了后台管理页面统计功能开发(1),从功能介绍,到接口请求分析和归类,最后是代码设计.经过上节内容的介绍,已经将业务逻辑和开发逻辑解释清楚,本节内容侧重于编程代码实现具体的功能. 当日增长数 ...
- hdu1845(a^b的因子和%p)
题目链接:http://poj.org/problem?id=1845 思路: 1.整数唯一分解定理: 任意正整数都有且只有一种方式写出其素因子的乘积表达式. a=(p1^k1)*(p2^k2)*(p ...
- C语言数据结构-链式栈的实现-初始化、销毁、长度、取栈顶元素、查找、入栈、出栈、显示操作
1.数据结构-链式栈的实现-C语言 //链式栈的链式结构 typedef struct StackNode { int data; struct StackNode *next; } StackNod ...
- getTasksWithCompletionHandler的用法
最近在学习iOS的NSSession的后台下载,使用getTasksWithCompletionHandler获取下载任务时候,发现一些问题,希望分享一下: 第一次写博客有点乱,大家不要见怪-- NS ...