【最小生成树】Codeforces 707B Bakery
题目链接:
http://codeforces.com/problemset/problem/707/B
题目大意:
给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面粉站的最短距离是多少。无法开店输出-1.
题目思路:
【最小生成树】
把边长按距离从小到大排序,出现的第一个只含一个面粉店的边为所求。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
struct xxx
{
int b,e,d;
}a[N];
bool mark[N];
bool cmp(xxx aa,xxx bb)
{
return aa.d<bb.d;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
while(~scanf("%d",&n))
{
mem(mark,);
scanf("%d%d",&m,&k);
for(i=;i<=m;i++)
scanf("%d%d%d",&a[i].b,&a[i].e,&a[i].d);
sort(a+,a++m,cmp);
for(i=;i<=k;i++)
{
scanf("%d",&x);
mark[x]=;
}
for(i=;i<=m;i++)
if(mark[a[i].b]+mark[a[i].e]==)break;
if(i>m)puts("-1");
else printf("%d\n",a[i].d);
}
return ;
}
/*
// //
*/
【最小生成树】Codeforces 707B Bakery的更多相关文章
- CodeForces 707B Bakery (水题,暴力,贪心)
题意:给定n个城市,其中有k个有仓库,问你在其他n-k个城市离仓库的最短距离是多少. 析:很容易想到暴力,并且要想最短,那么肯定是某一个仓库和某一个城市直接相连,这才是最优,所以只要枚举仓库,找第一个 ...
- CodeForces 707B Bakery
枚举. 枚举每一条边,如果发现边的一端$f[u]=1$,另一端$f[v]=0$,那么更新答案,取最小值就好了. #pragma comment(linker, "/STACK:1024000 ...
- Bakery CodeForces - 707B (最短路的思路题)
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. The ...
- codeforces 707B B. Bakery(水题)
题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include ...
- 【CodeForces - 707B】Bakery(思维水题)
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...
- 【Codeforces 707B】Bakery 水题
对每个storages找一下最短的相邻边 #include <cstdio> #define N 100005 #define inf 0x3f3f3f3f using namespace ...
- Codeforeces 707B Bakery(BFS)
B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- CodeForces–833B--The Bakery(线段树&&DP)
B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...
- CCPC-Wannafly Summer Camp 2019 Day1
A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...
随机推荐
- 纯javascript代码编写计算器程序
今天来分享一下用纯javascript代码编写的一个计算器程序,很多行业都能用到这个程序,例如做装修预算.贷款利率等等. 首先来看一下完成后的效果: 具体代码如下:(关注我的博客,及时获取最新WEB前 ...
- STM32串口通信USART1转USART2问题解决
使用的是STM32f103ZET6. 1.把文件main.c和usart.c中的所有usart1换成usart2 2.查看手册得知USART2的引脚是Tx->PA2,Rx->PA3,改变u ...
- Android Activity各启动模式的差异
Activity共有四种启动模式:standard,singleTop,singleTask,singleInstance 为了方便描述和理解,布局文件.Manifest文件和各个java文件如下: ...
- ViewPager和SwipeRefreshLayout之间嵌套使用时发生"事件"冲突
有时候我们会有一种需求,一个ViewPager有n个页面,每个页面是一个Fragment,在Fragment中使用了具有垂直滑动属性的控件,比如SwipeRefreshLayout!!! 这时二者之间 ...
- AFNetworking自带的解析图片的方法
首先要导入头文件 #import "UIKit+AFNetworking.h" 方法如下: [personImageView setImageWithURL:[NSURL URLW ...
- hdoj 4310 贪心
不知为毛,过不了 我的代码: #include<stdio.h> int main(){ int n,a[30],b[30],temp,i,j,s1,s2; double c[30]; w ...
- Codeforces 543B Destroying Roads(最短路)
题意: 给定一个n个点(n<=3000)所有边长为1的图,求最多可以删掉多少条边后,图满足s1到t1的距离小于l1,s2到t2的距离小于l2. Solution: 首先可以分两种情况讨论: 1: ...
- placeholder调整颜色
placeholder需要设定以下样式: ::-webkit-input-placeholder { /* WebKit browsers */ color: #999; } :-moz-placeh ...
- webservice拦截器 查看消息包(soap)
服务端: 1.获取EndpointImpl对象 2.调用EndpointImpl对象中的方法获取In拦截器 3.调用EndpointImpl对象中的方法获取out拦截器 4.添加自己的In拦截器与Ou ...
- C# ToString常用技巧总结
ToString是在开发中最常用的操作,其作用是将其它类型以字符串类型表示.例如: int i=2;i.ToString() //”2″Object o = new Object();o.ToStri ...