OpenJudge 1031 Lausanne Capitale Olympique
Lausanne Capitale Olympique
This problem will be judged on OpenJudge. Original ID: 1031
64-bit integer IO format: %lld Java class name: Main
Lausanne is a city in the French-speaking part of Switzerland. The headquarters of the International Olympic Committee (IOC) are located here; therefore Lausanne is also called the Olympic Capital.
As the London 2012 Olympics is coming, the IOC members frequently come to Lausanne to have meetings. Fortunately, IOC has a partner Lausanne Airways, which provides the IOC members with free flights.
Nevertheless, the IOC members live all over the world, and flights of Lausanne Airways are limited, so sometimes several transfers are unavoidable. For example, if a member lives in Shanghai, maybe he needs first fly to Beijing, then Paris, then Geneva, and finally arrived in Lausanne, which contains 3 transfers.
For convenience’s sake, the IOC members will always choose the trip with the minimum transfer times. However, due to the bad weather, some flights may be canceled, thus some members’ trip must be rescheduled. Lausanne Airways predicts that if there is only one flight canceled, then the minimum transfer times increases at most one for any IOC member.
Please check whether the above prediction is accomplished. Please note that all the flights mentioned above are two-way.
Input
Then there follows m lines, each of them contains two integers x, y (1 ≤ x, y ≤ n, x ≠ y), indicates there is a flight between city x and city y. It is guaranteed that there is at most one flight between any two cities, and these n cities are connected.
Output
If after a certain flight being canceled, these n cities are no longer connected, also output 0.
Sample Input
5 6
1 2
1 3
1 4
3 4
2 5
3 5
Sample Output
0 解题:。。哈哈,假设去掉边u->v,那么1到v就要改道,长度不能大于1啊,如果能够到v的变长不超过1,那么经过v的其他道路最长也不会增加超过1. 所以,看v的邻边,如果可以从v的邻点到此,那么就好了,要满足增长不大于1,那么1到v的邻点的长度应该为d[v]或者为d[v]-1。。。好了,直接枚举点的邻点就好了。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,next;
arc(int x = ,int y = -){
to = x;
next = y;
}
};
arc e[maxn*];
int head[maxn],d[maxn],q[maxn*];
int tot,n,m;
bool done[maxn];
void add(int u,int v){
e[tot] = arc(v,head[u]);
head[u] = tot++;
e[tot] = arc(u,head[v]);
head[v] = tot++;
}
void bfs(){
int hd = ,tl = ;
for(int i = ; i <= n; ++i) d[i] = INF;
d[] = ;
q[tl++] = ;
while(hd < tl){
int u = q[hd++];
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] > d[u] + ){
d[e[i].to] = d[u] + ;
q[tl++] = e[i].to;
}
}
}
}
int main() {
int u,v;
while(~scanf("%d %d",&n,&m)){
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; ++i){
scanf("%d %d",&u,&v);
add(u,v);
}
bfs();
bool ans = true;
for(int i = ; ans && i <= n; ++i){
int cnt = ;
for(int k = head[i]; ~k; k = e[k].next)
if(d[e[k].to] <= d[i] && ++cnt > ) break;
if(cnt < ) ans = false;
}
printf("%d\n",ans);
}
return ;
}
OpenJudge 1031 Lausanne Capitale Olympique的更多相关文章
- 【OpenJudge 8463】Stupid cat & Doge
http://noi.openjudge.cn/ch0204/8463/ 挺恶心的一道简单分治. 一开始准备非递归. 大if判断,后来发现代码量过长,决定大打表判断后继情况,后来发现序号不对称. 最后 ...
- 【OpenJudge 191】【POJ 1189】钉子和小球
http://noi.openjudge.cn/ch0405/191/ http://poj.org/problem?id=1189 一开始忘了\(2^{50}\)没超long long差点写高精度Q ...
- 【OpenJudge 1665】完美覆盖
http://noi.openjudge.cn/ch0405/1665/?lang=zh_CN 状压水题,手动转移 #include<cstdio> #include<cstring ...
- 【OpenJudge 1793】矩形覆盖
http://noi.openjudge.cn/ch0405/1793/ 好虐的一道题啊. 看数据范围,一眼状压,然后调了好长时间QwQ 很容易想到覆盖的点数作为状态,我用状态i表示至少覆盖状态i表示 ...
- BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6014 Solved: 2503[Submit ...
- Light OJ 1031 - Easy Game(区间dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...
- OpenJudge 2990:符号三角形 解析报告
2990:符号三角形 总时间限制: 1000ms 内存限制: 65536kB 描述 符号三角形的第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“ ...
- MySQLdb 1031 Error
Python import MySQLdb 有可能报:site-packages/pkg_resources.py:1031: UserWarning: /home/***/.python-eggs ...
- 深度优先搜索 codevs 1031 质数环
codevs 1031 质数环 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一个大小为N(N<=17)的质数环是 ...
随机推荐
- linux下的查找命令
whereis <程序名称> 查找软件的安装路径 -b 只查找二进制文件 -m 只查找帮助文件 -s 只查找源代码 -u 排除指定类型文件 -f 只显示文件名 -B <目录> ...
- Shell(三)流程控制
Shell 流程控制 和Java.PHP等语言不一样,sh的流程控制不可为空,如(以下为PHP流程控制写法): <?php if (isset($_GET["q"])) { ...
- 想说再见不容易,win7最新市占率依然超36%
微软正在通过努力让Windows 7用户升级至Windows 10,不过从目前的市占率来看,他们还是要加把劲了. 微软正在通过努力让Windows 7用户升级至Windows 10,不过从目前的市占率 ...
- Vue轮播图插件---Vue-Awesome-Swiper
轮播图插件 Vue-Awesome-Swiper 地址:https://github.com/surmon-china/vue-awesome-swiper 安装:npm install vue-aw ...
- Linux文件查找命令具体解释-which whereis find locate
原创BLog.转载请注明出处 http://blog.csdn.net/hello_hwc? viewmode=contents which命令 首先查看man which的说明 which - sh ...
- "浪潮杯"第六届ACM山东省省赛山科场总结
从空间拷过来的.尽管已经过去一个月了.记忆犹新 也算是又一次拾起这个blog Just begin 看着一群群大牛还有队友男神的省赛总结都出了 我最终也耐不住寂寞 来做个流水账抒抒情好了 第一次省赛 ...
- caffe中LetNet-5卷积神经网络模型文件lenet.prototxt理解
caffe在 .\examples\mnist文件夹下有一个 lenet.prototxt文件,这个文件定义了一个广义的LetNet-5模型,对这个模型文件逐段分解一下. name: "Le ...
- 【原创】使用Kettle的一些心得和经验
用kettle做etl也有段时间了,遇到很多问题,总结了一下. [关于版本的问题] kettle常用的版本有4.1和4.4,对于4.1版本: 1.该版本的兼容性有点差,在某些机器上运行会启动失败,或者 ...
- 编 写高性能的 SQL 语句注意事项
1. IS NULL 与 IS NOT NULL不能用 null 作索引, 任何包含 null 值的列都将不会被包含在索引中. 即使索引有多列这样的情况下,只要这些列中有一列含有 null,该列就会从 ...
- php创建图像具体步骤
php 的图像处理在验证码是最常见的,下面说下使用php创建图像的具体步骤. 简要说明:PHP 并不仅限于创建 HTML 输出, 它也可以创建和处理包括 GIF, PNG(推荐), JPEG, WBM ...