【t018】派对
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】派对的更多相关文章
- 洛谷银牛派对SPFA
题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...
- 【noip模拟赛4】Matrix67的派对 暴力dfs
[noip模拟赛4]Matrix67的派对 描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们 ...
- 【noip模拟赛4】Matrix67的派对 dfs
描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们安排在圆桌上.Matrix67的安排原则是,圆桌 ...
- 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 ...
- 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 ...
- 洛谷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 ...
- 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- 【BFS/DFS/YY】派对灯
[luogu1468]派对灯 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将 ...
- COGS 497——奶牛派对
奶牛派对 我们发现每头牛需要走的路程即为它到x的最短路+x到它的最短路. 转化: 于是这道题变成了一道典型的单源最短路问题,只需求出每个点到x的最短路dl,以及从x到此点的最短路d2,然后去找max( ...
随机推荐
- DirectX11笔记(十二)--Direct3D渲染8--EFFECTS
原文:DirectX11笔记(十二)--Direct3D渲染8--EFFECTS 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737 ...
- optim.py cs231n
n如果有错误,欢迎指出,不胜感激 import numpy as np """ This file implements various first-order upda ...
- umount报错解决device is busy
umount –a 报错device is busy如图 df -h 执行 umount -l /dev/sdk1 fuser -m -v /cache10 再查看卸载了
- 24种编程语言的Hello World程序
24种编程语言的Hello World程序 这篇文章主要介绍了 24 种编程语言的 Hello World 程序,包括熟知的 Java.C 语言.C++.C#.Ruby.Python.PHP 等编程语 ...
- NOIP2016提高A组模拟9.28总结
这次三道题都是可以AC的. 每道题思路都正确,但每道题都有细节没有注意. 第一题 1.没注意系数为1时可以省略系数: 2.没注意在第一项处理常数后,不能输出+号. 导致丢失20分:一定要多出特殊数据, ...
- spring-cloud-zuul跨域问题解决
问题发现 正常情况下,跨域是这样的: 1. 微服务配置跨域+zuul不配置=有跨域问题 2. 微服务配置+zuul配置=有跨域问题 3. 微服务不配置+zuul不配置=有跨域问题 4. 微服务不配置+ ...
- rsa加解密的内容超长的问题解决
一. 现象: 有一段老代码用来加密的,但是在使用key A的时候,抛出了异常:javax.crypto.IllegalBlockSizeException: Data must not be ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS)
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS) 学习目标 回顾复数,以及 ...
- laravle 事务
DB::beginTransaction(); try{ $name = 'abc'; $result1 = Test::create(['name'=>$name]); ...
- zabbix概述篇
zabbix监控系统概述 监控系统 决不允许未经监控的业务和服务的上线 基本功能 采样:获取客户端数据(主动和被动模式) 存储 展示 告警 监控通道 ssh/telnet:无agent snmp:简单 ...