Time Limit: 1 second

Memory Limit: 256 MB

【问题描述】

N头牛要去参加一场在编号为X(1≤X≤n)的牛的农场举行的派对(1≤N≤1000),有M(1≤M≤100000)条有向道路,每条路长ti(1≤ti≤100);
每头牛都必须参加完派对后回到家,每头牛都会选择最短路径,求这N头牛的最短路径(一个来回)中最长的一条的长度。
特别提醒:可能有权值不同的重边。

【输入格式】

第一行:N,M,X;
第二~M+1行:Ai,Bi,Ti,表示有一条从Ai到Bi的路,长度为Ti

【输出格式】

最长最短路的长度。

【输入样例1】

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

【输出样例1】

10

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=t018

【题意】



中文题

【题解】



在反图和正图上各自跑一遍spfa;

求出x点到其他点的最短路;

正图和反图加起来就是这个人到x再回家的最短路了;

枚举取最大值就好;



【完整代码】

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int M = 109000;
const int N = 1100; struct abc
{
int en,w,nex;
}; int n,m,x,tot[2]={0},dis[2][N],fir[2][N];
abc g[2][M];
queue <int> dl;
bool exsit[N]; void add(int p,int x,int y,int z)
{
g[p][++tot[p]].nex = fir[p][x];
fir[p][x] = tot[p];
g[p][tot[p]].en = y,g[p][tot[p]].w = z;
} void spfa(int p)
{
memset(dis[p],0x3f3f3f3f,sizeof dis[p]);
memset(exsit,false,sizeof exsit);
dis[p][x] = 0;
dl.push(x),exsit[x] = true;
while (!dl.empty())
{
int xx = dl.front();
dl.pop(),exsit[xx] = false;
for (int i = fir[p][xx];i;i = g[p][i].nex)
{
int y = g[p][i].en;
if (dis[p][y]>dis[p][xx]+g[p][i].w)
{
dis[p][y] = dis[p][xx] + g[p][i].w;
if (!exsit[y])
{
exsit[y] = true;
dl.push(y);
}
}
}
}
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(m);rei(x);
rep1(i,1,m)
{
int x,y,z;
rei(x);rei(y);rei(z);
add(0,x,y,z),add(1,y,x,z);
}
spfa(0),spfa(1);
int ma = dis[0][1]+dis[1][1];
rep1(i,2,n)
if (ma<dis[0][i]+dis[1][i])
ma = dis[0][i]+dis[1][i];
printf("%d\n",ma);
return 0;
}

【t018】派对的更多相关文章

  1. 洛谷银牛派对SPFA

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

  2. 【noip模拟赛4】Matrix67的派对 暴力dfs

    [noip模拟赛4]Matrix67的派对   描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们 ...

  3. 【noip模拟赛4】Matrix67的派对 dfs

    描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们安排在圆桌上.Matrix67的安排原则是,圆桌 ...

  4. P1821 [USACO07FEB]银牛派对Silver Cow Party

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

  5. poj3268 Silver Cow Party(农场派对)

    题目描述 原题来自:USACO 2007 Feb. Silver N(1≤N≤1000)N (1 \le N \le 1000)N(1≤N≤1000) 头牛要去参加一场在编号为 x(1≤x≤N)x(1 ...

  6. 洛谷P1821 [USACO07FEB]银牛派对Silver Cow Party

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

  7. 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party

    P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  8. 【BFS/DFS/YY】派对灯

    [luogu1468]派对灯 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将 ...

  9. COGS 497——奶牛派对

    奶牛派对 我们发现每头牛需要走的路程即为它到x的最短路+x到它的最短路. 转化: 于是这道题变成了一道典型的单源最短路问题,只需求出每个点到x的最短路dl,以及从x到此点的最短路d2,然后去找max( ...

随机推荐

  1. Node环境变量 process.env 的那些事儿

    前言 这两天在和运维GG搞部署项目的事儿. 碰到一个问题就是,咱们的dev,uat,product环境的问题. 因为是前后端分离,所以在开发和部署的过程中会有对后端接口的域名的切换问题.折腾了一下午, ...

  2. Sentinel 1.5.0 正式发布,引入 Reactive 支持

    近日,流控降级组件 Sentinel 的又一个里程碑版本 1.5.0 正式发布. 该版本引入 Reactive 的支持,并提供多项新特性与改进.从 1.5.0 版本开始,Sentinel 仅支持 JD ...

  3. Linux常用命令6 压缩解压命令

    .zip是Linux和Windows共有的压缩格式 1.压缩解压命令:gzip 命令英文原意:GNU zip   命令所在路径:/bin/gzip 执行权限:所有用户 语法: gzip [文件]   ...

  4. JVM学习篇章(一)

    熟悉Java开发的同学,应该都知道jvm是什么,---它就是Java虚拟机,今天我们就学习一下:  内存分配原则:  常用的监控命令

  5. Spring_自动组件扫描和 基于注解配置bean

    自动组件扫描 启用Spring组件扫描功能. 使用@Component注释来表示这是类是一个自动扫描组件.  package com.tanlei.dao; import org.springfram ...

  6. 为何需要apigee edge

    http://apigee.com/docs/gateway-services/content/what-apigee-edge 越来越多的服务商在网上提供服务,通过各种标准的接口对来自手机.电脑.p ...

  7. JasperStudio 输出pdf 出错。

    发表于 2008-09-23 09:35:15 楼主net.sf.jasperreports.engine.JRException: Error retrieving field value from ...

  8. shell学习(23)- diff和patch

    diff命令可以生成两个文件之间的差异对比. (1) 先创建下列用于演示的文件.文件 1:version1.txt this is the original text line2 line3 line ...

  9. 【NS2】在linux下安装低版本GGC

    1.下载安装包,cd到文件所在目录 sudo dpkg -i gcc41-compat-4.1.2-ubuntu1210_i386.deb g++41-compat-4.1.2_i386.deb 2. ...

  10. CAD专用卸载修复工具,一键完全彻底卸载删除CAD软件的专用卸载工具

    Autodesk CAD卸载工具(AUTO Uninstaller)是专门为了针对Autodesk CAD软件卸载不干净而导致CAD安装失败问题进行研发的Autodesk CAD一键卸载工具.现在虽然 ...