题目描述

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island ai and Island bi.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.

Constraints
3≤N≤200 000
1≤M≤200 000
1≤ai<bi≤N
(ai,bi)≠(1,N)
If i≠j, (ai,bi)≠(aj,bj).

输入

Input is given from Standard Input in the following format:
N M
a1 b1
a2 b2
:
aM bM

输出

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

样例输入

3 2
1 2
2 3

样例输出

POSSIBLE

分析:反正只需要两次即可,直接判断第一个节点后和第n个节点前有没有通。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,m,a,b;
bool vis[],flag;
void init(){
cin>>n>>m;
fill(vis,);
range(i,,m){
cin>>a>>b;
if(flag)continue;
if(a==){
flag=vis[b];
vis[b]=true;
}
else if(b==n){
flag=vis[a];
vis[a]=true;
}
}
}
void solve(){
cout<<(flag?"POSSIBLE":"IMPOSSIBLE")<<endl;
}
int main() {
init();
solve();
return ;
}

Cat Snuke and a Voyage --AtCoder的更多相关文章

  1. Atcoder At Beginner Contest 068 C - Cat Snuke and a Voyage

    C - Cat Snuke and a Voyage Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem State ...

  2. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  3. AtCoder Beginner Contest 068

    A - ABCxxx 题意: 给出n,输出“ABCn”就可以了,纯水题. B - Break Number 题意: 给出n,找出从1到n的闭区间内能够被2整除最多次的数. 思路: 直接模拟. 代码: ...

  4. 【AtCoder】ARC079

    ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...

  5. 数学 SRM 690 Div1 WolfCardGame 300

    Problem Statement      Wolf Sothe and Cat Snuke are playing a card game. The game is played with exa ...

  6. すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)

    Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. ...

  7. Fennec VS. Snuke --AtCoder

    题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...

  8. AtCoder Regular Contest 068E:Snuke Line

    题目传送门:https://arc068.contest.atcoder.jp/tasks/arc068_c 题目翻译 直线上有\(0-m\)这\(m+1\)个点,一共有\(m\)辆火车.第\(i\) ...

  9. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

随机推荐

  1. ipv4配置

  2. Java面向对象---泛型

    概念 泛型可以解决数据类型的安全问题,主要原理是在类声明的时候通过一个标识表示类中某个属性的类型或者是某个方法的返回值及参数类型. 格式 访问权限 class 类名称<泛型,泛型...>{ ...

  3. 2612. [FHZOI 2017]被窃的项链

    2612. [FHZOI 2017]被窃的项链 ★★★   输入文件:stolen_necklace.in   输出文件:stolen_necklace.out   简单对比时间限制:1 s   内存 ...

  4. Lucene.Net 精品教程

    http://www.cnblogs.com/piziyimao/archive/2013/01/31/2887072.html

  5. 从shell(终端)中退出python

    从shell(终端)中退出python: 1.输入命令行:$ exit() 2.快捷键: ctrl+Z

  6. [oldboy-django][2深入django]rest-framework教程

    # rest-framework教程 - settings.py INSTALL-APPS = [ 'snippets', # app 'rest-framework', ] - 创建model # ...

  7. 【Luogu】P2403所驼门王的宝藏(强连通分量)

    题目链接 想到缩点后DP这题就迷之好做 横天门就点向该行连一条边 纵门就点向该列连一条边 ziyou门直接枚举……map搞搞……话说ziyou门为啥是违规内容不让我发布? 然后缩点,DP,1A 不过写 ...

  8. NetScaler通过DHCP服务器获取IP地址

    NetScaler通过DHCP服务器获取IP地址 DHCP 选项参考 https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp ...

  9. 关于fixed定位的一些错误看法纠正

    之前由于一些误导,一直感觉fixed这个定位在ie8下面是会出现兼容问题的,今天发现这个想法太绝对了,它只是在ie7 8 的怪异模式下面会出现兼容问题 解决这个问题可以通过用absolute来模拟fi ...

  10. 洛谷 [P3496] BLO

    割点 首先 tarjan 求割点, 对于不是割点的点, 答案是 2 * (n-1) 有序,所以要乘 2 对于是割点的点, 答案是删去该点后所有连通块的个数加上 n-1 在乘 2 #include &l ...