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)的质数环是 ...
随机推荐
- 安装Nginx的各种报错的解决
如题,本人环境Ubuntu14.0虚拟机,安装一个nginx服务器来运行我的fastDfs文件管理的.但是安装出现了各种问题: sudo ./configure --prefix=/usr/local ...
- java实现多个数字求和_图形化界面
一,设计思想 1,通过简单的窗口实现多个数字的输入与输出. 2,可通过用户输入数字的数量来实现多个数字的求和. 3,定义整型数组变量number和字符串型数组变量integer,将输入的字符串变量赋给 ...
- VUE使用中踩过的坑
前言 vue如今可谓是一匹黑马,github star数已居第一位!前端开发对于vue的使用已经越来越多,它的优点就不做介绍了,本篇是我对vue使用过程中以及对一些社区朋友提问我的问题中做的一些总结, ...
- 关于fromkeys的用法
分享一个小知识点: 1. Python 中关于dict的fromkeys方法: 1. fromkeys是用于重构字典 2. 至少传一个参数,第一个参数为新建dict的key,如果第一个参数为字典,那么 ...
- 通过wget下载tomcat
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.42/bin/apache-tomcat-8.0.42.tar.gz 注意:下载之前确 ...
- JAVA 多线程知识总结(一)
一,线程的生命周期以及五种基本状态 关于JAVA线程的生命周期,首先看一下下面这张图 上图中基本上囊括了Java中多线程各重要知识点.掌握了上图中的各知识点,Java中的多线程也就基本上掌握了. Ja ...
- 【codeforces 500E】New Year Domino
[题目链接]:http://codeforces.com/problemset/problem/500/E [题意] 有n个多米诺骨牌; 你知道它们的长度; 然后问你,如果把第i骨牌往后推倒,然后要求 ...
- Docker 管理工具的选择:Kubernetes 还是 Swarm?
[编者的话]选择Kubernetes 或者 Swarm 就像在将 Linux 桌面发行版的范围缩小到两个后选出一个最喜欢的.哪个更满足你的需要如何才是决定因素. [3 天烧脑式基于Docker的CI/ ...
- (转)彻底学会使用epoll(一)——ET模式实现分析
注:之前写过两篇关于epoll实现的文章,但是感觉懂得了实现原理并不一定会使用,所以又决定写这一系列文章,希望能够对epoll有比较清楚的认识.是请大家转载务必注明出处,算是对我劳动成果的一点点尊重吧 ...
- Error: Password file read access must be restricted: /etc/cassandra/jmxremote.password
在配置JMX远程访问的时候,设置jmxremote.password文件权限,修改该文件时添加写权限,chmod +w jmxremote.password ,放开角色信息那俩行的注释,保存,再使用c ...