CodeForces 707B Bakery
枚举。
枚举每一条边,如果发现边的一端$f[u]=1$,另一端$f[v]=0$,那么更新答案,取最小值就好了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int INF=0x7FFFFFFF;
const int maxn=;
int n,m,k;
bool f[maxn];
struct X{int u,v,w;}s[maxn]; int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=m;i++) scanf("%d%d%d",&s[i].u,&s[i].v,&s[i].w);
for(int i=;i<=k;i++)
{
int x; scanf("%d",&x);
f[x]=;
}
int ans=INF;
for(int i=;i<=m;i++)
{
if(f[s[i].u]&&f[s[i].v]) continue;
if(!f[s[i].u]&&!f[s[i].v]) continue;
ans=min(ans,s[i].w);
}
if(ans==INF) printf("-1\n");
else printf("%d\n",ans);
return ;
}
CodeForces 707B Bakery的更多相关文章
- 【最小生成树】Codeforces 707B Bakery
题目链接: http://codeforces.com/problemset/problem/707/B 题目大意: 给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面 ...
- CodeForces 707B Bakery (水题,暴力,贪心)
题意:给定n个城市,其中有k个有仓库,问你在其他n-k个城市离仓库的最短距离是多少. 析:很容易想到暴力,并且要想最短,那么肯定是某一个仓库和某一个城市直接相连,这才是最优,所以只要枚举仓库,找第一个 ...
- 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出发的 ...
随机推荐
- 4 MySQL与PHP连接
目录: 1. 连接概述2. 创建php文件进行MySQL连接3. 查看连接效果 1. 连接概述 上文讲述了LAMP开发模型,并且使用AppServ进行安装.这时候就要体现优势了.本节将介绍在直接使用P ...
- BDD
Binding business requirements to .NET code http://www.specflow.org/ 行为驱动开发 BDD:Behavior Driven Devel ...
- ASP.NET Web API是如何根据请求选择Action的?[上篇]
ASP.NET Web API是如何根据请求选择Action的?[上篇] Web API的调用请求总是针对定义在某个HttpController中的某个Action方法,请求响应的内容来源于调用目标A ...
- 如何用程序删除win 7下SYSTEM权限的目录
win7系统由于安装程序等操作,可能会在系统中留下一些所有权限是SYSTEM角色的目录,例如我的系统以前在C盘的QQ卸载后的遗留文件(下图). System是Windows系统中最高权限角色(组),比 ...
- iOS获取程序运行平台
下面这个博客里面写的很清楚 http://blog.sina.com.cn/s/blog_890a737301014fim.html
- xhEditor入门基础
一.下载最新版本xhEditor:http://xheditor.com/download (官网无法下载,CSDN提供下载:http://download.csdn.net/detail/itmy ...
- 使用JAVA进行MD5加密后所遇到的一些问题
前言:这几天在研究apache shiro如何使用,这好用到了给密码加密的地方,就碰巧研究了下java的MD5加密是如何实现的,下面记录下我遇到的一些小问题. 使用java进行MD5加密非常的简单,代 ...
- C#代码搜索器
WEBUS2.0 In Action - [源代码] - C#代码搜索器 最近由于工作的需要, 要分析大量C#代码, 在数万个cs文件中搜索特定关键词. 这是一项非常耗时的工作, 用Notepad++ ...
- <mate>标签中属性/值的各个意思
<mate>标签中属性/值的各个意思 HTML 4 name 属性 1.<mate name="author" content="" /> ...
- python alembic which comes from SQLalchemy
alembic it's tutorial: http://alembic.readthedocs.org/en/latest/tutorial.html