P1821 [USACO07FEB]银牛派对Silver Cow Party
题目描述
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?
寒假到了,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。
输出格式:
一个整数,表示最长的最短路得长度。
输入输出样例
说明

神奇的反向存图操作
为了不写两遍spfa
可用x<<1,x<<1|1 这种方式将一个点拆成两个点存
这样正着走反着走都可以啦
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = 4e5+;
// name*******************************
int n,m,x;
int a,b,t;
struct edge
{
int to,next,w;
} e[N];
int tot=;
int Head[N];
int vis[N];
queue<int>que;
int dis[N];
int ans=;
// function******************************
void add(int u,int v,int w)
{
e[++tot].to=v;
e[tot].next=Head[u];
Head[u]=tot;
e[tot].w=w;
}
void spfa(int x)
{
que.push(x);
vis[x]=;
dis[x]=;
while(!que.empty())
{
int u=que.front();
vis[u]=;
que.pop();
for(int p=Head[u]; p; p=e[p].next)
{
int v=e[p].to;
int w=e[p].w;
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
if(!vis[v])
{
vis[v]=;
que.push(v);
}
}
}
}
}
//***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n>>m>>x;
me(dis,);
For(i,,m)
{
scanf("%d%d%d",&a,&b,&t);
add(a<<,b<<,t);
add(b<<|,a<<|,t);
}
spfa(x<<);
spfa(x<<|);
For(i,,n)
{
ans=max(ans,dis[i<<]+dis[i<<|]);
} cout<<ans; return ;
}
P1821 [USACO07FEB]银牛派对Silver Cow Party的更多相关文章
- 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- 洛谷 P1821 [USACO07FEB]银牛派对Silver Cow Party 题解
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- 洛谷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 ...
- luogu 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 ...
- 【luogu P1821 [USACO07FEB]银牛派对Silver Cow Party】 题解
题目链接:https://www.luogu.org/problemnew/show/P1821 反向多存一个图,暴力跑两遍 #include <cstdio> #include < ...
- 洛谷 P1821 [USACO07FEB]银牛派对Silver Cow Party
银牛派对 正向建图+反向建图, 两边跑dijkstra,然后将结果相加即可. 反向建图以及双向建图的做法是学习图论的必备思想. #include <iostream> #include & ...
- 「Luogu 1821」[USACO07FEB]银牛派对Silver Cow Party
更好的阅读体验 Portal Portal1: Luogu Portal2: POJ Description One cow from each of N farms \((1 \le N \le 1 ...
- [USACO07FEB]银牛派对Silver Cow Party
题目简叙: 寒假到了,N头牛都要去参加一场在编号为X(1≤X≤N)的牛的农场举行的派对(1≤N≤1000),农场之间有M(1≤M≤100000)条有向路,每条路长Ti(1≤Ti≤100). 每头牛参加 ...
- [USACO07FEB]银牛派对Silver Cow Party---最短路模板题
银牛排队 对于我这种蒟蒻来说,还是不要跑一次单元最短路.跑两次好写呀(- ̄▽ ̄)- 而题目中是有向图.如果如果按照题意进行最短路的话.就会出现一个单终点最短路和一个单起点最短路 对于单起点自然就是套模 ...
随机推荐
- PDO中的事务处理
基本原理和步骤其实都是一样的(可参看上一篇“MySQL的事务处理”),PDO中的事务处理就是调用PDO对象的三个方法: 开启事务:beginTransaction 回滚操作:rollBack 执行操作 ...
- Textarea输入字数限制(兼容iOS&安卓)
最近在做一个微信公众号的页面,其中有对textarea做输入字数限制,而且需要兼容iOS和安卓手机,下面直接贴代码: <!DOCTYPE html> <html lang=" ...
- SharePoint Server 2013安装
坑死人不偿命的呀 在Windows Server 2012 R2上安装SharePoint Server 2013,安装了半天,结果卡在“Windows Server AppFabric”安装错误上, ...
- 语义SLAM的数据关联和语义定位(一)
语义SLAM和多传感器融合是自动驾驶建图和定位部分比较热门的两种技术.语义SLAM中,语义信息的数据关联相较于特征点的数据关联有所不同.我们一般用特征描述子的相似性来匹配和关联不同图像中的特征点.特征 ...
- SQLServer 学习笔记之超详细基础SQL语句 Part 9
Sqlserver 学习笔记 by:授客 QQ:1033553122 -----------------------接Part 8------------------- 3 范式的概念 第一范式的目标 ...
- Python+Selenium笔记(十六)屏幕截图
(一) 方法 方法 简单说明 save_screenshot(filename) 获取当前屏幕截图并保存为指定文件 filename:路径/文件名 get_screenshot_as_base64 ...
- 解决IE下select option不支持display none样式
万恶的IE,option竟然不支持display样式,想到的解决思路有二个: 1.ajax联动查询 2.jQuery的remove().after()方法 方法1的不好之处是初始页面,需要显示全部IP ...
- alpha阶段 代码结构及技术难点简介
我们的产品是安卓端app,所以目前主要就是用Android Studio来进行代码开发. Android Studio的项目的结构还是比较清晰的,如下图,主要就是java文件夹内的代码部分(.java ...
- Scala包的使用
package big.data.analyse.scala.classes /** * Created by zhen on 2018/9/15. */ object Packages { def ...
- 从零起步做到Linux运维经理,你必须管好的23个细节
不想成为将军的士兵,不是好士兵-拿破仑 如何成为运维经理?成为运维经理需要什么样的能力?我想很多运维工程师都会有这样的思考和问题. 如何成为运维经理.一般来说,运维经理大概有两种出身,一种是从底层最基 ...