题目描述

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. Java面向对象---泛型

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

  2. 洛谷P1079 Vigenère 密码

    题目链接:https://www.luogu.org/problemnew/show/P1079

  3. 介绍 Active Directory 域服务 (AD DS) 虚拟化

    TechNet 库 Windows Server Windows Server 2012 R2 和 Windows Server 2012 服务器角色和技术 Active Directory Acti ...

  4. 史上最权威的 Activiti 框架学习

        Activiti5 是 由 Alfresco 软件在 2010 年 5 月 17 日发布的业务流程管理( BPM) 框架,它是覆盖了业务流程管理.工作流.服务协作等领域 的一个开源的.灵活的. ...

  5. Python框架之Django学习笔记(十六)

    Django框架之表单(续) 今天简直无力吐槽了,去了香山,结果和网上看到的简直是天壤之别啊,说好的香山的枫树呢?说好的香山的红叶呢?说好的漫山遍野一片红呢?本以为在山上,一口气爬上去,沿路基本都是翠 ...

  6. MFC定时关机程序的实现2-添加启动项到注册表

    虽然上一篇实现了的定时关机,但是还不够完善,比如开机自动启动,然后按照配置的时间定时关机,并最小化到任务栏. 先来说开机启动怎么实现,开机启动实现的方法有好几种,比如直接在开始菜单启动项里添加一个程序 ...

  7. 爬虫:Scrapy3 - Items

    Item 对象是种简单的容器,保存了爬取到得数据.其提供了类似于词典(dictionary-like)的API以及用于声明可用字段的简单语法. 声明Item import scrapy class P ...

  8. leetcode NO.171 Excel表列序号 (python实现)

    来源 https://leetcode-cn.com/problems/excel-sheet-column-number/description/ 题目描述 给定一个Excel表格中的列名称,返回其 ...

  9. Mybatis通过接口的方式实现增删改查

    导入jar包 [mybatis] [oracle] 生成数据库 1.添加Mybatis的配置文件mybatis-config.xml 在src目录下创建一个mybatis-config.xml文件,如 ...

  10. 移动端布局rem em

    1.概念 em作为font-size的单位时,其代表父元素的字体大小,em作为其他属性单位时,代表自身字体大小 rem作用于非根元素时,相对于根元素字体大小:rem作用于根元素字体大小时,相对于其出初 ...