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 ≤ XN). 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。的更多相关文章

  1. POJ 3268 Silver Cow Party (Dijkstra)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13982   Accepted: 6307 ...

  2. POJ 3268 Silver Cow Party (Dijkstra + 优先队列)

    题意:由n个牧场,编号1到n.每个牧场有一头牛.现在在牧场x举办party,每头牛都去参加,然后再回到自己的牧场.牧场之间会有一些单向的路.每头牛都会让自己往返的路程最短.问所有牛当中最长的往返路程是 ...

  3. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  4. POJ 3268 Silver Cow Party (最短路径)

    POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...

  5. POJ 3268 Silver Cow Party (双向dijkstra)

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  6. POJ 3268 Silver Cow Party 最短路

    原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  7. POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】

    Silver Cow Party Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  8. DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards

    题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...

  9. POJ 3268 Silver Cow Party (最短路dijkstra)

    Silver Cow Party 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/D Description One cow fr ...

随机推荐

  1. curl 测试web站点的响应时间

    curl -s -w "\n"::%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total} ...

  2. .bash_profile和.bashrc的什么区别

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...

  3. spring jdbc 源码

    类:org.springframework.jdbc.core.JdbcTemplate public <T> T execute(PreparedStatementCreator psc ...

  4. mytest 截图

  5. Android如何使用API

    转自:http://www.cnblogs.com/vanezkw/archive/2012/07/03/2574559.html 本文针对Android开发如何使用API文档进行一些经验分享. 1. ...

  6. PowerDesigner中逆向工程将数据库中comment赋值到name

    '------------------------------------------------------------ ' '脚本功能: ' PowerDesigner中逆向工程完成后,将数据库中 ...

  7. js插入节点appendChild和insertBefore

    首先 从定义来理解 这两个方法: appendChild() 方法:可向节点的子节点列表的末尾添加新的子节点.语法:appendChild(newchild) insertBefore() 方法:可在 ...

  8. 转 :Vim文件编码识别与乱码处理

    Vim文件编码识别与乱码处理   在 Vim 中,有四个与编码有关的选项,它们是:fileencodings.fileencoding.encoding 和 termencoding.在实际使用中,任 ...

  9. 单词接龙(dragon)

    单词接龙(dragon) 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次) ...

  10. OpenGL学习-------visual studio 2010配置和第一个OpenGL程序讲解

    OpenGL作为当前主流的图形API之一,它在一些场合具有比DirectX更优越的特性. 1.与C语言紧密结合. OpenGL命令最初就是用C语言函数来进行描述的,对于学习过C语言的人来讲,OpenG ...