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 ;
}

OpenJudge 1031 Lausanne Capitale Olympique的更多相关文章

  1. 【OpenJudge 8463】Stupid cat & Doge

    http://noi.openjudge.cn/ch0204/8463/ 挺恶心的一道简单分治. 一开始准备非递归. 大if判断,后来发现代码量过长,决定大打表判断后继情况,后来发现序号不对称. 最后 ...

  2. 【OpenJudge 191】【POJ 1189】钉子和小球

    http://noi.openjudge.cn/ch0405/191/ http://poj.org/problem?id=1189 一开始忘了\(2^{50}\)没超long long差点写高精度Q ...

  3. 【OpenJudge 1665】完美覆盖

    http://noi.openjudge.cn/ch0405/1665/?lang=zh_CN 状压水题,手动转移 #include<cstdio> #include<cstring ...

  4. 【OpenJudge 1793】矩形覆盖

    http://noi.openjudge.cn/ch0405/1793/ 好虐的一道题啊. 看数据范围,一眼状压,然后调了好长时间QwQ 很容易想到覆盖的点数作为状态,我用状态i表示至少覆盖状态i表示 ...

  5. BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组

    1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6014  Solved: 2503[Submit ...

  6. Light OJ 1031 - Easy Game(区间dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...

  7. OpenJudge 2990:符号三角形 解析报告

    2990:符号三角形 总时间限制:  1000ms       内存限制:  65536kB 描述 符号三角形的第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“ ...

  8. MySQLdb 1031 Error

    Python import MySQLdb 有可能报:site-packages/pkg_resources.py:1031: UserWarning: /home/***/.python-eggs ...

  9. 深度优先搜索 codevs 1031 质数环

    codevs 1031 质数环  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description 一个大小为N(N<=17)的质数环是 ...

随机推荐

  1. [置顶] Linux 常用命令集锦

    出处:http://www.vaikan.com/what-are-the-most-useful-swiss-army-knife-one-liners-on-unix/ Linux命令行里的&qu ...

  2. 洛谷4623 [COCI2012-2013#6] BUREK

    题目描述 给定N个三角形,和M条直线,直线要么平行于X轴,要么平行于Y轴,问这M条直线 分别经过多少个三角形内部 (注意是内部即分开的两个多边形的面积均大于零). 输入输出格式 输入格式: 第一行一个 ...

  3. HDU 2048 神、上帝以及老天爷( 错排 )

    链接:传送门 思路:错排模板,典型错排问题,n个人所有人都不会抽到自己的方案数为 Dn = (n-1) * (Dn-1 + Dn-2) /******************************* ...

  4. luogu 自适应Simpson2

    自适应simpson2 题意 求一个不定积分 解法 画出函数的图像,可以知道其在0处函数值趋近于 $ + \infty $,在10处趋近于0,所以我们从0积分到10就可以了(保险起见,积到15) 代码 ...

  5. 窗口管理工具 screen

    简介 Screen是一款用于命令行终端切换的自由软件 用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换 GNU Screen可以看作是窗口管理器的命令行界面版本 它提供了统一的管 ...

  6. Docker学习总结(13)——从零开始搭建Jenkins+Docker自动化集成环境

    本文只简单标记下大概的步骤,具体搭建各个部分的细节,还请自行搜索.第一.二部分只是对Jenkins和Docker的简单介绍,熟悉的同学请直接跳到第三部分. 一.关于Jenkins Jenkins简介 ...

  7. PHP编译时错误解决:Don&#39;t know how to define struct flock on this system, set --enable-opcache=no

    在编辑PHP5.6.1时出现了这个错误: Don't know how to define struct flock on this system, set --enable-opcache=no 解 ...

  8. 使用dispatch_once实现单例

    很多人实现单例会这样写: @implementation XXClass + (id)sharedInstance { static XXClass *sharedInstance = nil; @s ...

  9. nyoj--814--又见拦截导弹(动态规划+贪心)

    又见拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系 ...

  10. FriendlyARM交叉工具链以及编译第一个arm9应用

    不记录什么都会忘光!!!这两天又要用到开发板来做项目,可是好久没有碰了,最近一直在搞上层的东东,对rails和前端感兴趣,我这是不要毕业的节奏了吗?好吧,既然什么都忘光掉了,那就干脆来个痛快,重新装机 ...