CodeForces 707B Bakery】的更多相关文章

题目链接: http://codeforces.com/problemset/problem/707/B 题目大意: 给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面粉站的最短距离是多少.无法开店输出-1. 题目思路: [最小生成树] 把边长按距离从小到大排序,出现的第一个只含一个面粉店的边为所求. // //by coolxxx //#include<bits/stdc++.h> #include<iostream> #include<al…
题意:给定n个城市,其中有k个有仓库,问你在其他n-k个城市离仓库的最短距离是多少. 析:很容易想到暴力,并且要想最短,那么肯定是某一个仓库和某一个城市直接相连,这才是最优,所以只要枚举仓库,找第一个城市,然后更新答案即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib&g…
枚举. 枚举每一条边,如果发现边的一端$f[u]=1$,另一端$f[v]=0$,那么更新答案,取最小值就好了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map…
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 so…
题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include &l…
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同的城市编号为a1, a2,…,ak. 不幸的是,玛莎居住的那个国家的法律禁止在任何一个有仓库的城市开设面包店.她只能在另一个n - k城市中的一个开这家店,当然,面粉配送也要付费——从仓库到面包房每走一公里,玛莎就得支付1卢布. 形式上,玛莎将支付x卢布,如果她将打开面包店在一些城市b (ai≠b每…
对每个storages找一下最短的相邻边 #include <cstdio> #define N 100005 #define inf 0x3f3f3f3f using namespace std; struct edge{ int to,next,w; }e[N<<1]; int head[N],cnt; void add(int u,int v,int w){ e[++cnt]=(edge){v,head[u],w}; head[u]=cnt; } int n,m,k; int…
B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 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,…
B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的.所以能删的铁路有该铁路长度不等于1到该节点的最短路的,相等的时候,如果该节点的入度非1,也可以删去. #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #in…