(简单) POJ 3268 Silver Cow Party,Dijkstra。
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
正向边一次最短路,反向边一次就好了。。。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue> using namespace std; const int INF=10e8;
const int MaxN=; struct Node
{
int v,val; Node(int _v=,int _val=):v(_v),val(_val) {}
bool operator < (const Node &a) const
{
return val>a.val;
}
}; struct Edge
{
int v,cost; Edge(int _v=,int _cost=):v(_v),cost(_cost) {}
}; vector <Edge> E[][MaxN]; void Dijkstra(int type,int lowcost[],int n,int start)
{
priority_queue <Node> que;
Node qtemp;
int u,v,c,len; for(int i=;i<=n;++i)
{
lowcost[i]=INF;
}
lowcost[start]=; que.push(Node(start,)); while(!que.empty())
{
qtemp=que.top();
que.pop(); u=qtemp.v; len=E[type][u].size(); for(int i=;i<len;++i)
{
v=E[type][u][i].v;
c=E[type][u][i].cost; if(lowcost[u]+c<lowcost[v])
{
lowcost[v]=lowcost[u]+c;
que.push(Node(v,lowcost[v]));
}
}
}
} inline void addEdge(int type,int u,int v,int c)
{
E[type][u].push_back(Edge(v,c));
} int ans1[MaxN],ans2[MaxN];
int maxans; int main()
{
int N,M,X;
int a,b,c; while(~scanf("%d %d %d",&N,&M,&X))
{
for(int i=;i<=M;++i)
{
scanf("%d %d %d",&a,&b,&c); addEdge(,a,b,c);
addEdge(,b,a,c);
} for(int i=;i<=N;++i)
ans1[i]=ans2[i]=;
maxans=-; Dijkstra(,ans1,N,X);
Dijkstra(,ans2,N,X); for(int i=;i<=N;++i)
if(ans1[i]+ans2[i]>maxans)
maxans=ans1[i]+ans2[i]; cout<<maxans<<endl;
} return ;
}
(简单) POJ 3268 Silver Cow Party,Dijkstra。的更多相关文章
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13982 Accepted: 6307 ...
- POJ 3268 Silver Cow Party (Dijkstra + 优先队列)
题意:由n个牧场,编号1到n.每个牧场有一头牛.现在在牧场x举办party,每头牛都去参加,然后再回到自己的牧场.牧场之间会有一些单向的路.每头牛都会让自己往返的路程最短.问所有牛当中最长的往返路程是 ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- POJ 3268 Silver Cow Party (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ 3268 Silver Cow Party (最短路dijkstra)
Silver Cow Party 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/D Description One cow fr ...
随机推荐
- 一篇非常适合git入门的文章
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579 ...
- mysql 连接两列
以下划线符号,连接两列,作为查询结果: SELECT CONCAT(col_1,'_',col_2) FROM yourtable
- Error configuring application listener of class 报错 解决
Error configuring application listener of class 次错误是由于工程没有贬义Class文件造成的,clean一下编译一下工程,clean之后进入项目目录查看 ...
- phpStudy环境配置多个站点,绑定域名
经常做网站的朋友,往往要在自已的电脑同时建立多个站点,而phpstudy这款软件就能很好的解决这个问题,大家看下图 点击上图中的 其它选项菜单 ,就会弹出下面的对话框,然后点击 站点域名管理 然 后在 ...
- Ubuntu下修改DNS重启也能用的方法
1.通过修改:/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)实现 内容填上需要修改的nameserver
- c++绘图软件<一>
准备写一个绘图软件,参考了三层架构(表现层.业务逻辑层.数据访问层). //////////////////////////////////////////////////////////////// ...
- 小师妹问 easyUI mergeCells 行合并后表头和内容对不齐
公司来了一个做easyUI的妹子,恰好那妹子是和我一个学校的,有一天下班妹子在超时买东西正好巧遇,然后妹子就问了问题,随便说手机卡需要我帮忙刷机,然后就问手机买了多久, 多少钱,刚买的时候好用不,然后 ...
- vmware卸载问题
1. VMware版本问题:http://www.wuji8.com/meta/15866846.html2. VMware卸载问题:http://www.veryhuo.com/a/view/716 ...
- cocos2d CCLOG格式符号表
使用示例: CCLOG(); CCLOG(, 650000L); CCLOG(); CCLOG(); CCLOG(, , , , ); CCLOG("Floats: %4.2f %.0e % ...
- J2SE基本数据结构
1.J2SE中的常用数据结构对象的继承关系如下图 Collection ........|--------List ........|..........|----------ArrayList .. ...