原题:

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
作者: 陈越
单位: 浙江大学
时间限制: 400ms
内存限制: 64MB
代码长度限制: 16KB

思路:

一道普通的AOE网的题,求关键路径。用临接表实现。

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXV 101
struct edge
{
    int w; //权
    int v; //指向的点
};
vector<edge> G[MAXV];       //临接表
int N,M,inDegree[MAXV]={0},ve[MAXV]={0};    //顶点数,边数,入度

int topoSort()
{
    int num=0;      //入队次数
    queue<int> q;
    for(int i=0;i<N;i++)
    {
        if(inDegree[i]==0)
            q.push(i);          //将度为0的结点入队
    }
    while(!q.empty())
    {
        int u=q.front();      //取出队首结点
        //cout<<u<<endl;
        q.pop();

        for(int i=0;i<G[u].size();i++)
        {
            int v=G[u][i].v;
            inDegree[v]--;     //入度减1
            if(inDegree[v]==0)
                q.push(v);     //入队
            if(ve[u]+G[u][i].w>ve[v]){
                ve[v]=ve[u]+G[u][i].w;
            }
        }
        G[u].clear();        //清边,非必需
        num++;
    }
    if(num == N)
        return 1;
    else
        return 0;
}

int main()
{
    cin>>N;
    cin>>M;
    for(int i=0;i<M;i++)
    {
        int e,s,l;
        cin>>e;
        cin>>s;
        cin>>l;
        edge temp={l,s};
        G[e].push_back(temp);
        inDegree[s]++;
    }
    if(1==topoSort())
        {
            int max=0;
            for(int i=0;i<N;i++)
            {
                if(ve[i]>max)
                    max=ve[i];
            }
            cout<<max;
        }
    else
        cout<<"Impossible";
    return 0;
}

08-图8 How Long Does It Take的更多相关文章

  1. ISE和Modelsim联合仿真(转)

    相信很多人会遇到过这个问题,不知如何让ISE调用Modelsim进行仿真.我也迷糊了不少时间,查查找找,终于弄明白了,所以有了本文,和大家分享一下.我尽量讲得详细点儿,多多上图. 我的环境:Windo ...

  2. ISE和Modelsim联合仿真(详细步骤讲解)

    ISE和Modelsim联合仿真(转) 地址:http://www.cnblogs.com/feitian629/archive/2013/07/13/3188192.html 相信很多人会遇到过这个 ...

  3. 3ds Max制作客厅场景实例教程

    附件系列 (图01) 让我们回顾一下场景:一个房间包括下列一件件家具, 在中间的一张小桌子,在房间的角落的一个小桌子,有一个垃圾桶和一个带镜子的边桌,有一个烛台.还有一个挂钟,窗帘,沙发和带手臂的椅子 ...

  4. 自定义控件(视图)2期笔记08:自定义控件之 9patch图说明

    1. 何为 9patch图 ?     它是一个对png图片做处理的一个工具,能够为我们生成一个"*.9.png"的图片:所谓"*.9.png"这是Androi ...

  5. Beta阶段第2周/共2周 Scrum立会报告+燃尽图 08

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2389] 版本控制:https://git.coding.net/liuyy08 ...

  6. 2018.08.29 NOIP模拟 table(拓扑排序+建图优化)

    [描述] 给出一个表格,N 行 M 列,每个格子有一个整数,有些格子是空的.现在需要你 来做出一些调整,使得每行都是非降序的.这个调整只能是整列的移动. [输入] 第一行两个正整数 N 和 M. 接下 ...

  7. ViewPager轮播图

    LoopViewPagerLayout无限轮播 项目地址:https://github.com/why168/LoopViewPagerLayout 支持三种动画: 支持修改轮播的速度: 支持修改滑动 ...

  8. iOS系列 基础篇 08 文本与键盘

    iOS系列 基础篇 08 文本与键盘 目录: 1. 扯扯犊子 2. TextField 3. TextView 4. 键盘的打开和关闭 5. 打开/关闭键盘的通知 6. 键盘的种类 7. 最后再扯两句 ...

  9. 【玩转单片机系列001】 08接口双色LED显示屏驱动方式探索

    前些日子,从淘宝上购得一块08接口的双色LED显示屏(打算做个音乐频谱显示器),捣鼓了好几天,终于搞清楚了其控制原理,在这里做个总结,算是备忘吧. 1.LED显示屏的扫描方式 LED显示屏的扫描方式有 ...

  10. C#+JQuery+.Ashx+百度Echarts实现全国省市地图和饼状图动态数据图形报表的统计

    在目前的一个项目中,需要用到报表表现数据,这些数据有多个维度,需要同时表现出来,同时可能会有大量数据呈现的需求,经过几轮挑选,最终选择了百度的echarts作为报表基础类库.echarts功能强大,界 ...

随机推荐

  1. 基于HTML5及WebGL开发的2D3D第一人称漫游进行碰撞检测

    为了实现一个基于HTML5的场景小游戏,我采用了HT for Web来实现,短短200行代码,我就能实现用“第一人称”来操作前进后退上下左右,并且实现了碰撞检测. 先来看下实现的效果:http://h ...

  2. 使用spark与MySQL进行数据交互的方法

    在项目中,遇到一个场景是,需要从Hive数据仓库中拉取数据,进行过滤.裁剪或者聚合之后生成中间结果导入MySQL. 对于这样一个极其普通的离线计算场景,有多种技术选型可以实现.例如,sqoop,MR, ...

  3. 超级详细 一听就会:利用JavaScript jQuery实现图片无限循环轮播(不借助于轮播插件)

    前言 作为一个前端工程师,无论公司是什么行业,无论你做什么端,基本都会遇到一个避不开的动画效果:循环轮播.做轮播并不难,市场上的轮播插件有很多,其中比较著名的是swiper,使用也非常简单.但轮播插件 ...

  4. EF异常探究(An entity object cannot be referenced by multiple instances of IEntityChangeTracker.)

    今天在改造以前旧项目时出现了一项BUG,是由于以前不规范的EF写法所导致.异常信息如下: "An entity object cannot be referenced by multiple ...

  5. C++开发象棋一 绘制棋盘

    这是我要和大家分享的基于C++和MFC开发的一个象棋程序,目的是练习编程实践和大家分享同时希望大家能给出指教. 进入主题 一.棋盘分析 这是我绘制的棋盘,棋盘的组成由9条竖线和10条横线构成.这儿我们 ...

  6. LeetCode 119. Pascal's Triangle II (杨辉三角之二)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  7. JavaScript判断变量数据类型

    一.JS中的数据类型 1.数值型(Number):包括整数.浮点数. 2.布尔型(Boolean) 3.字符串型(String) 4.对象(Object) 5.数组(Array) 6.空值(Null) ...

  8. Ubuntu下通过makefile生成静态库和动态库简单实例

    本文转自http://blog.csdn.net/fengbingchun/article/details/17994489 Ubuntu环境:14.04 首先创建一个test_makefile_gc ...

  9. Fibonacci(...刷的前几道题没有记博客的习惯,吃了大亏)

    Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  10. Linux 进程后台运行的几种方式(screen)

    Ctrl+z/bg/nohup/setsid/& 在Linux中,如果要让进程在后台运行,一般情况下,我们在命令后面加上&即可,实际上,这样是将命令放入到一个作业队列中了: ./rsy ...