这题看不太懂题目啊~  参考的http://blog.csdn.net/qq_26437925/article/details/49420089?locationNum=6&fps=1

先放着吧。

#include  "iostream"
#include "vector"
using namespace std;
int in_degree[]; /* 记录图的各个节点的入度 */
struct Node {
int e;
int cost;
};
vector<Node>v[];
int early[];
int n, m;
bool toplogicSort() {
int start = -;
for (int i = ; i < n; i++) {
if (in_degree[i] == ) {
start = i;
break;
}
}
if (start == -) { /* 没有入度为0的点 完不成项目*/
return false;
}
early[start] = ;
int sum = ;
int num = ;
int newP = start;
while (num != n - ) {
int len = v[newP].size(); /* 出度 */
for (int i = ; i < len; i++) {
int e = v[newP][i].e;
int cost = v[newP][i].cost;
in_degree[e]--;
if (early[newP] + cost > early[e]) {
early[e] = early[newP] + cost;
}
}
in_degree[newP] = -; /* 删除该节点 */
newP = -;
for (int i = ; i < n; i++) {
if (in_degree[i] == ) {
newP = i;
break;
}
}
if (newP == -)
return false;
if (early[newP] > sum)
sum = early[newP];
num++;
}
cout << sum << endl;
return true;
}
int main() {
Node node;
cin >> n >> m;
for(int i = ; i < n; i++){
in_degree[i] = ;
early[i] = ;
}
while (m--) {
int s, e, l;
cin >> s >> e >> l;
node.e = e;
node.cost = l;
v[s].push_back(node);
in_degree[e]++;
}
if (!toplogicSort())
cout << "Impossible" << endl;
}

PTA 5-12 How Long Does It Take (25分)的更多相关文章

  1. PTA 04-树4 是否同一棵二叉搜索树 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/712 5-4 是否同一棵二叉搜索树   (25分) 给定一个插入序列就可以唯一确定一棵二 ...

  2. PTA 02-线性结构3 Reversing Linked List (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/664 5-2 Reversing Linked List   (25分) Given a ...

  3. PTA 09-排序3 Insertion or Heap Sort (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/676 5-14 Insertion or Heap Sort   (25分) Accor ...

  4. PTA 01-复杂度2 Maximum Subsequence Sum (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/663 5-1 Maximum Subsequence Sum   (25分) Given ...

  5. PTA 字符串关键字的散列映射(25 分)

    7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...

  6. PTA 1067 Sort with Swap(0, i) (25 分)(思维)

    传送门:点我 Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasin ...

  7. PTA 是否同一棵二叉搜索树(25 分)

    是否同一棵二叉搜索树(25 分) 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始 ...

  8. PTA 11-散列2 Hashing (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/679 5-17 Hashing   (25分) The task of this pro ...

  9. PTA 11-散列1 电话聊天狂人 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/722 5-14 电话聊天狂人   (25分) 给定大量手机用户通话记录,找出其中通话次数 ...

  10. PTA 10-排序6 Sort with Swap(0, i) (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/678 5-16 Sort with Swap(0, i)   (25分) Given a ...

随机推荐

  1. c++函数内部可以返回函数内部定义的指针 但是不能返回函数内部定义的数组

    1.返回数组 // demo.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<stdio.h> char *m ...

  2. BZOJ 3901 棋盘游戏 解题报告

    这题有个重要性质: 我们设 Flag[i][j] 表示 (i, j) 是否被奇数个操作所覆盖, 也就是操作次数对 2 取模. 设 x = (n + 1) / 2. 那么对于所有的合法的操作方案, 令 ...

  3. 用PYTHON硬写SOCKET

    这个文章的系列很有意思,练练~~: http://python.jobbole.com/82763/ :) 第一步,最简单的SERVER和CLIENT.感觉和写JAVA,C的最简单的一样一样的,,看来 ...

  4. JavaSE replaceAll 方法

    private String srcStr = "index\\.php\\?action=";//要替换的原字符串 private String destStr = " ...

  5. UVA 515 King

    差分约束系统的第一个题目,看了落花大神的博客后,对差分约束有了一定了解,关键在于建图,然后就是判断是否存在负权回路. 关于差分约束系统的解释详见维基百科:http://zh.wikipedia.org ...

  6. Linux下使用clock_gettime给程序计时

    http://www.cnblogs.com/daqiwancheng/archive/2010/07/01/1769522.html

  7. 用Unity3.0+MVC4搭建项目

    新年快乐!又是新的一年到来了,我好久没有在园子里面做笔记啦,由于工作上的事,还好年前把该做的都完善了,于是就写了辞职信.由于家庭原因,不得不离职,在春节期间呢,我放松了几天,去这里去那里的,朋友们喜欢 ...

  8. jquery parent()和parents()区别

    parent(exp) 取得一个包含着所有匹配元素的唯一父元素的元素集合. 你可以使用可选的表达式来筛选. 查找段落的父元素中每个类名为selected的父元素. HTML 代码: <div&g ...

  9. Oracle系列之索引

    涉及到表的处理请参看原表结构与数据  Oracle建表插数据等等 Oracle索引.权限 介绍 为什么添加了索引后,会加快查询速度呢? 索引是用于加速数据存取的数据对象.合理的使用索引可以大大降低i/ ...

  10. Apache ‘mod_pagespeed’模块跨站脚本漏洞

    漏洞名称: Apache ‘mod_pagespeed’模块跨站脚本漏洞 CNNVD编号: CNNVD-201310-677 发布时间: 2013-11-05 更新时间: 2013-11-05 危害等 ...