Lausanne Capitale Olympique

Time Limit: 1000ms
Memory Limit: 65536KB

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

The first line contains two integers nm (1 ≤ n ≤ 10000, 1 ≤ m ≤ 100000), indicates that the IOC members live in n different cities, numbered from 1 to n, which 1 stands for Lausanne and 2~n for other cities.
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 the prediction is accomplished, output 1; otherwise output 0.
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 ;
}

最新文章

  1. 阿里云服务器上配置并使用: PHP + Redis + Mysql 从配置到使用
  2. android 获取屏幕宽度和高度
  3. 【安装Express】CentOS7 下安装NodeJs+Express+MongoDB+Redis
  4. Discuz对不起,您安装的不是正版应用的解决办法
  5. CI框架区分前后台
  6. IOS 今天学到太多的知识了,赶快记录下来
  7. c++必读
  8. 2013年7月份第3周51Aspx源码发布详情
  9. 15、NFC技术:使用Android Beam技术传输文件
  10. linux目录下各文件夹作用
  11. The method getTextContent() is undefined for the type Node
  12. .net core2.0获取host的方法
  13. MyBatis Generator使用com.mysql.cj.jdbc.Driver遇到的问题
  14. elasticsearch技术解析与实战(一) 入门和索引
  15. 优化myeclipse启动速度以及解决内存不足问题
  16. 在开发中写一些tool来提升自己的效率
  17. Javascript设计模式笔记
  18. (转)IntelliJ Idea 常用快捷键列表 for win
  19. HTML5编写规范
  20. Mac-WIFI总是断网

热门文章

  1. HDU-2955 Robberies 浮点数01背包 自变量和因变量位置互换
  2. 模板 FFT 快速傅里叶变换
  3. linux软链接与硬链接详解
  4. SVN提交代码时报405 Method Not Allowed
  5. [luogu] P3202 [HNOI2009]通往城堡之路(贪心)
  6. js实现鼠标吸附线条效果
  7. jquery访问ashx文件示例
  8. mybatis批量插入oracle大量数据记录性能问题解决
  9. 多本Web前端深度修炼书籍(提供网盘下载链接)
  10. cocos2dx-3.0创建Android项目时遇到的错误。