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)的质数环是 ...
随机推荐
- 一些BFC
我们可能会遇到这样的一些问题,比如:子元素浮动,父元素高度塌陷:父元素跟随子元素一起移动等 这是我们可以通过触发BFC来解决这样的问题. BFC为"块级格式化上下文".它是一个独立 ...
- hbase的hbase-site.xml配置文件
<property> <name>hbase.rootdir</name> <value>hdfs://server110/hbase</valu ...
- 【BZOJ 1305】[CQOI2009]dance跳舞
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 男生和女生每个人都分身成两个节点 即x[1],x[2]和y[1],y[2] 然后如果i和j不相互喜欢 那么add(x[i][2],y ...
- table的创建
results为table的行信息 columnNames 是table列名 //创建并初始化table: table =new JTable(results,columNames); //设置ta ...
- Picking up Jewels
Picking up Jewels There is a maze that has one entrance and one exit. Jewels are placed in passages ...
- Python菜鸟晋级12----多线程
Python 多线程 多线程类似于同一时候执行多个不同程序,多线程执行有例如以下长处: 使用线程能够把占领长时间的程序中的任务放到后台去处理. 用户界面能够更加吸引人.这样比方用户点击了一个butto ...
- IOS 数据存储之 SQLite具体解释
在IOS开发中常常会须要存储数据,对于比較少量的数据能够採取文件的形式存储,比方使用plist文件.归档等,可是对于大量的数据,就须要使用数据库,在IOS开发中数据库存储能够直接通过SQL訪问数据库, ...
- jquery/zepto在插件编写上的几点区别
1. 自定义事件的命名空间 jq的时间命名空间是用点“.”,而zepto是用冒号“:” 如 //jquery $(this).trigger('cusevent.pluginname'); //zep ...
- 配置 NTP 时间服务器
对于我们当前这种案例,主要目标是把 z01 这台服务器设置为时间服务器,剩下的 z02,z03 这两台机器同步 z01 的时间,我们需要这样做的原因是因为,整个集群架构中的时间,要保持一致. ** 检 ...
- App.config配置详解
经上一篇文章https://www.cnblogs.com/luna-hehe/p/9104701.html发现自己对配置文件很是不了解,同样还是查了半天终于发现另一片宝贵文档https://www. ...