PTA 5-12 How Long Does It Take (25分)
这题看不太懂题目啊~ 参考的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分)的更多相关文章
- PTA 04-树4 是否同一棵二叉搜索树 (25分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/712 5-4 是否同一棵二叉搜索树 (25分) 给定一个插入序列就可以唯一确定一棵二 ...
- 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 ...
- 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 ...
- 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 ...
- PTA 字符串关键字的散列映射(25 分)
7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...
- 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 ...
- PTA 是否同一棵二叉搜索树(25 分)
是否同一棵二叉搜索树(25 分) 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始 ...
- 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 ...
- PTA 11-散列1 电话聊天狂人 (25分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/722 5-14 电话聊天狂人 (25分) 给定大量手机用户通话记录,找出其中通话次数 ...
- 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 ...
随机推荐
- 使用Yeoman搭建 AngularJS 应用 (1) —— 介绍
原文地址:http://yeoman.io/learning/ Yeoman 是一个通用的可以创建多种应用的基架系统.它帮助用户快速搭建新的项目,并且可以简化已存在项目的维护过程. Yeoman是不限 ...
- 深入研究java.lang.ProcessBuilder类
深入研究java.lang.ProcessBuilder类 一.概述 ProcessBuilder类是J2SE 1.5在java.lang中新添加的一个新类,此类用于创建操作系统进程,它 ...
- C# List<> 删除
List<string> l = new List<string>() { "A1", "A2", "A3", &q ...
- SecureCRT自动登陆到服务器的脚本以及脚本编写简单说明
http://blog.csdn.net/marising/article/details/6409196 Secure用SSH登陆服务器时,如果服务器较多,登陆一次很麻烦,所以,可以自己编写VBSc ...
- Java缓存--JCS
添加外部包: jcs-1.3.jar concurrent-10.3.jar cache.cff # optional region "myCache" specific conf ...
- 目标识别:Bag-of-words表示图像
BOW (bag of words) 模型简介 Bag of words模型最初被用在文本分类中,将文档表示成特征矢量.它的基本思想是假定对于一个文本,忽略其词序和语法.句法,仅仅将其看做是一些词汇的 ...
- Using FireMonkey Layouts
FireMonkey has many layout controls to choose from. Come learn the differences and how to use them t ...
- 页面上动态编译及执行java代码
本文地址:http://www.cnblogs.com/liaoyu/p/real-time-compile-and-run-java-code-web-app.html 最近看到同事在页面上编译和执 ...
- Document字段发生变化后,报的错
2016-10-11 15:27:47,828 [ERROR] [main] SpringApplication:838 - Application startup failedorg.springf ...
- ActionBar官方教程(11)自定义ActionBar的样式(含重要的样式属性表及练习示例)
Styling the Action Bar If you want to implement a visual design that represents your app's brand, th ...