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 ...
随机推荐
- python eval函数
eval()函数十分强大,官方demo解释为:将字符串str当成有效的表达式来求值并返回计算结果. 可以把字符串转为list.tuple .dict 等数据类型 1.把字符串转为字典 ####### ...
- Automotive Security的一些资料和心得(3):Vehicular Security技术
1. Overview 1.1. Secure Hardware Extension (SHE) 基本结构:ECU里面有一块单独的Secure Zone.Secure Zone里面是SHE模块.SHE ...
- android开发之---文字居中---android中去掉标题栏
1. 让textView里面的内容水平居中 : android:gravity="center_horizontal" 2. 让textView控件在它的父布局里水平居中 ...
- Windows Phone 8 开发环境搭建
原地址:http://blog.csdn.net/md521/article/details/11015139 Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8 ...
- loadrunner 脚本和replaylog中的中文乱码问题(转载)
解决这个问题必须认识到一个事实就是,loadrunner和测试服务器交换数据使用的是utf8格式,但是展现在replaylog中是使用gb2312格式,而且在脚本中如何使用web_reg_find的时 ...
- HDU - 3594 Cactus
这是一个有向仙人掌的题目,要求判定给定的图是不是强连通图,而且每一条边只能出现在一个环中,这里有一个介绍有向仙人掌的文档:http://files.cnblogs.com/ambition/cactu ...
- *[topcoder]LittleElephantAndBalls
http://community.topcoder.com/stat?c=problem_statement&pm=12758&rd=15704 topcoder的题经常需要找规律,而 ...
- [jobdu]用两个栈实现队列
思路比较简单.就是当要pop的时候,如果s2为空,才把s1的转过来.总之就是区分一下此时s2为空和非空的情况. http://ac.jobdu.com/problem.php?pid=1512 #in ...
- asp.net 框架初接触
1. 在web层的Default.aspx里只有最基本的UI代码 2. 在web层的Default.aspx.cs里第一行创建一个用户业务对象UserBO (注意添加引用,下同) protected ...
- 基于dojo模板的widget
参考:http://niweiwei.iteye.com/blog/1539863 http://dojotoolkit.org/reference-guide/1.8/dijit/_Template ...