链接:

https://vjudge.net/problem/CodeForces-707B

题意:

Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

思路:

选一个最小的边,同时两边的点满足一个是蛋糕店,一个是仓库.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 1e5+10; struct Edge
{
int u, v, w;
bool operator < (const Edge& that) const
{
return this->w < that.w;
}
}edge[MAXN];
int Vis[MAXN];
int n, m, k; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1;i <= m;i++)
cin >> edge[i].u >> edge[i].v >> edge[i].w;
int v;
for (int i = 1;i <= k;i++)
{
cin >> v;
Vis[v] = 1;
}
int res = -1;
sort(edge+1, edge+1+m);
for (int i = 1;i <= m;i++)
{
if (Vis[edge[i].u] != Vis[edge[i].v])
{
res = edge[i].w;
break;
}
}
cout << res << endl; return 0;
}

CodeForces-707B(思维)的更多相关文章

  1. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  2. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  3. 【最小生成树】Codeforces 707B Bakery

    题目链接: http://codeforces.com/problemset/problem/707/B 题目大意: 给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面 ...

  4. Codeforces 1060E(思维+贡献法)

    https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...

  5. Queue CodeForces - 353D (思维dp)

    https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...

  6. codeforces 1244C (思维 or 扩展欧几里得)

    (点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...

  7. 【Codeforces 707B】Bakery 水题

    对每个storages找一下最短的相邻边 #include <cstdio> #define N 100005 #define inf 0x3f3f3f3f using namespace ...

  8. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  9. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  10. CodeForces 625A 思维

    题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a< ...

随机推荐

  1. Screen Painter 程序设计

    一.Screen 的创建及维护, TCode:SE51 输入程序名称,单击[建立], 程序1000为SAP预留屏幕号,屏幕号必须定义1000外的其他数字,且最多不超过四位, 本例定义屏幕为SAP预留屏 ...

  2. beanFactory 设计模式 Bean 生命周期

    写在前面的话 适用读者:有一定经验的,本文不适合初学者,因为可能不能理解我在说什么 文章思路:不会一开始就像别的博客文章那样,Bean 的生命周期,源码解读(给你贴一大堆的源码).个人觉得应该由问题驱 ...

  3. char* a = "abc" 和 char a[] = "abc" 之间的区别

    char* a = "abc"; 声明了一个字符类型的指针a,并为它赋值初始值为"abc",a的值是字符串"abc"的首地址[第一个字符的地 ...

  4. centos v7.0解决乱码

    [root@localhost ~]# ll 鎬荤敤閲4-rw-------. 1 root root 1045 8鏈 24 21:17 anaconda-ks.cfg [root@localhost ...

  5. Pytorch实现Top1准确率和Top5准确率

    之前一直不清楚Top1和Top5是什么,其实搞清楚了很简单,就是两种衡量指标,其中,Top1就是普通的Accuracy,Top5比Top1衡量标准更“严格”, 具体来讲,比如一共需要分10类,每次分类 ...

  6. [ASP.NET] 解决点击控件下载文件没有响应的问题

    下载文件的方法是使用http响应输出流来实现的,使用到了response.write() 导致下载文件时点击控件出错,没有响应,也获取不了文件 是因为在母版页使用了updatepanel,因此回传时发 ...

  7. spring boot-5.配置文件注入

    配置文件注入这一部分内容主要有以下几点内容: 1.全局配置文件值注入 2.自定义配置文件值注入 3.自定义的Spring 配置文件生效 (1)首先介绍全局配置文件的值注入,全局配置文件值注入有两种方式 ...

  8. python-2:爬取某个网页(虎扑)帖子的标题做词云图

    关键词:requests,BeautifulSoup,jieba,wordcloud 整体思路:通过requests请求获得html,然后BeautifulSoup解析html获得一些关键数据,之后通 ...

  9. PostgreSQL-优化之分表

    分表概述 数据库分表,就是把一张表分成多张表,物理上虽然分开了,逻辑上彼此仍有联系. 分表有两种方式:水平分表,即按列分开:垂直分表,即按行分开 优势 1. 查询速度大幅提升 2. 删除数据速度更快 ...

  10. 编辑器IDE之VSCode

    很多时候面临换项目组,公司内部换等等,需要清除之前的权限,电脑更换等... 确实很烦人,所以记录也是给自己下次更加快速方便的使用 插件安装 个人常用的一些插件,发现好用的会更新 插件名 功能 vsco ...