sdut 2498【aoe 网上的关键路径】
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2498
代码超时怎么破:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int mapx[][],ve[],vl[],h[],m,k;
stack<int>zhan;
queue<int>e;
queue<int>l;
void tuopu();
void gengxin();
int main()
{
while(cin>>m>>k)
{
memset(mapx,,sizeof(mapx));
memset(h,,sizeof(h));
memset(ve,,sizeof(ve));
memset(vl,,sizeof(vl));
int i,u,v,countx;
for(i=; i<=k; i++)
{
cin>>u>>v>>countx;
mapx[u][v]=countx;
h[v]++;
}
tuopu();
gengxin();
}
}
void tuopu()
{
int i,flag=,j;
while(flag=!flag)
{
for(i=; i<=m; i++)
{
if(h[i]==)
{
flag=;
h[i]=-;
zhan.push(i);
for(j=; j<=m; j++)
if(mapx[i][j]!=)
h[j]--;
//更新 ve数组
int y=;
for(j=; j<=m; j++)
{
if(mapx[j][i]!=)
{
if(mapx[j][i]+ve[j]>y)
{
y=mapx[j][i]+ve[j];
}
}
}
ve[i]=y;
}
}
}
/*while(!zhan.empty())
{
cout<<zhan.top()<<" ";
zhan.pop();
}
cout<<endl;*/
//输出ve 数组
/*for(i=1;i<=m;i++)
cout<<ve[i]<<" ";
cout<<endl;*/
}
void gengxin()
{
//更新 vl数组和v数组,e数组
int i,j;
int x=ve[m];
for(i=; i<=m; i++)
vl[i]=x;
int maxx=x,z[],top=-,z1[];
while(!zhan.empty())
{
x=zhan.top();
int y=maxx;
for(i=; i<=m; i++)
{
if(mapx[x][i]!=)
{
if(y>vl[i]-mapx[x][i])
y=vl[i]-mapx[x][i];
}
}
vl[x]=y;
zhan.pop();
}
//验证输出vl数组
/*for(i=1;i<=m;i++)
cout<<vl[i]<<" ";
cout<<endl;*/
int countx=,q1=;
for(i=; i<=m; i++)
{
for(j=; j<=m; j++)
{
if(mapx[i][j]!=)
{
//e.push(ve[i]);
//l.push(vl[j]-mapx[i][j]);
if(ve[i]==vl[j]-mapx[i][j])
{
if(j==m)
q1=;
countx=countx+mapx[i][j];
z[++top]=i;
z1[top]=j;
break;
}
}
}
if(q1==)break;
}
cout<<countx<<endl;
for(i=; i<=top; i++)
cout<<z[i]<<" "<<z1[i]<<endl;
//验证输出
/*
while(!e.empty())
{
cout<<e.front()<<" ";
e.pop();
}
cout<<endl;
while(!l.empty())
{
cout<<l.front()<<" ";
l.pop();
}
cout<<endl;*/
}
/*测试数据
9 11
1 2 6
1 3 4
1 4 5
2 5 1
3 5 1
4 6 2
5 7 8
5 8 7
6 8 4
7 9 2
8 9 4
*/
sdut 2498【aoe 网上的关键路径】的更多相关文章
- SDUT 2498 AOE网上的关键路径
AOE网上的关键路径 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 一个无环的有向图称为无 ...
- sdut AOE网上的关键路径(spfa+前向星)
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2498&cid=1304 题目描述 一个无环的有向图称为无环图(Directed Acyc ...
- SDUTOJ 2498 数据结构实验之图论十一:AOE网上的关键路径
题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2498.html 题目大意 略. 分析 ...
- AOE网上的关键路径(最长路径 + 打印路径)
题目描述 一个无环的有向图称为无环图(Directed Acyclic Graph),简称DAG图. AOE(Activity On Edge)网:顾名思义,用边表示活动的网,当然它也是DAG ...
- 数据结构实验之图论十一:AOE网上的关键路径【Bellman_Ford算法】
Problem Description 一个无环的有向图称为无环图(Directed Acyclic Graph),简称DAG图. AOE(Activity On Edge)网:顾名思义,用边 ...
- SDUT 2498-AOE网上的关键路径(spfa+字典序路径)
AOE网上的关键路径 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 一个无环的有向图称为无环图(Directed Acycl ...
- SDUT-2498_AOE网上的关键路径
数据结构实验之图论十一:AOE网上的关键路径 Time Limit: 2000 ms Memory Limit: 65536 KiB Problem Description 一个无环的有向图称为无环图 ...
- AOE网与关键路径简介
前面我们说过的拓扑排序主要是为解决一个工程能否顺序进行的问题,但有时我们还需要解决工程完成需要的最短时间问题.如果我们要对一个流程图获得最短时间,就必须要分析它们的拓扑关系,并且找到当中最关键的流程, ...
- AOE网络的关键路径问题
关于AOE网络的基本概念可以参考<数据结构>或者search一下就能找到,这里不做赘述. 寻找AOE网络的关键路径目的是:发现该活动网络中能够缩短工程时长的活动,缩短这些活动的时长,就可以 ...
随机推荐
- How to tile small texture image onto page as its background
You don’t need to set a big size image as the background of pages if the image is texture or uniform ...
- Android 手势水平监听判断
package com.zihao.ui; import com.zihao.R; import android.os.Bundle; import android.app.Activity; imp ...
- apache poi 生成excel
ExcelBuilder.Java package com.coracle.yk.xmanager.util.poi; import com.coracle.yk.xframework.util.Bl ...
- 注册页面的js验证
简单的用户注册页面:(html) 包含用户名格式验证.邮箱格式验证.确认密码一致性验证和必填项验证.(纯javascript) <center> <h1>用户注册</h1 ...
- c#.netGr idView1在div不局中
<div style="margin:0 auto;text-align:center;" >//可以用GridView剧中 <asp:GridView ID=& ...
- python: extend (扩展) 与 append (追加) 的差别
>>> li = ['a', 'b', 'c'] >>> li.extend(['d', 'e', 'f']) >>> li ['a', 'b', ...
- Appium+Robotframework实现Android应用的自动化测试-1:Appium在Windows中的安装
让我们开始在Windows中开始安装Appium吧,Appium在OS X中的具体安装后面的文章会介绍. 另外,官网上说先要装Node.js,还要装Apache Ant和Apache Maven,Gi ...
- 一些笔试题(C/C++)
1.there are two variables, don't use if.. else or ?: or switch or other judgement statements,find ou ...
- SuperIndicator 专做轮播图库,没有之一,支持轮播图无限循环
github地址:https://github.com/hejunlin2013/SuperIndicator SuperIndicator a superindicatorlibray for vi ...
- 【资料】Boost的资料
http://blog.csdn.net/pongba/article/details/1561110