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 ...
随机推荐
- java连接数据库时出现如下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.driver at org.apache.catalina.loader.WebappClassLoa ...
- csuoj 1351: Tree Counting
这是一个动态规划的题: 当初想到要用dp,但是一直想不到状态转移的方程: 题解上的原话: 动态规划,设 g[i]表示总结点数为 i 的方案种数,另设 f[i][j]表示各个孩子的总结点数为i,孩子的个 ...
- Python中文全攻略
原文链接:http://blog.csdn.net/mayflowers/archive/2007/04/18/1568852.aspx 1. 在Python中使用中文 在Python中 ...
- bulkTransfer通讯必须注意的问题:bulk buffer size(16K)
Android USB host与HID使用bulkTransfer通讯接收和发送的数据长度不会超过16384,这个问题困扰了我很长一段时间,终于发现问题所在,不是出在我的程序设计,也不是硬件的发送/ ...
- 集合对象(NSSet)
main.m #import <Foundation/Foundation.h> @interface NSSet(printInteger) -(void)printSet; @end ...
- paip.无线路由器的无线接入WAN方式WDS设置大法
paip.无线路由器的无线接入WAN方式WDS设置大法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn. ...
- hdu4597Play Game(记忆化)
链接 通化邀请赛的题 貌似不怎么难 记忆化DP 状态方程类似于2维的 只是变成了4维 每次有四种方向去搜 取最棒的 判断好边界条件 #include <iostream> #includ ...
- Oracle MySQL Server 拒绝服务漏洞
漏洞名称: Oracle MySQL Server 拒绝服务漏洞 CNNVD编号: CNNVD-201401-316 发布时间: 2014-01-22 更新时间: 2014-01-22 危害等级: 中 ...
- Apache ‘mod_pagespeed’模块跨站脚本漏洞
漏洞名称: Apache ‘mod_pagespeed’模块跨站脚本漏洞 CNNVD编号: CNNVD-201310-677 发布时间: 2013-11-05 更新时间: 2013-11-05 危害等 ...
- Linux下归档与压缩工具笔记
tar具体使用笔记 归档工具 tar 语法 功能 选项 常见搭配 压缩工具 bzip2 工具 使用方法 gzip 工具 zip 工具 归档工具 tar tar是一个开源的Linux/Unix中最广泛使 ...